Home

# Class goog.messaging.PortChannel

A wrapper for several types of HTML5 message-passing entities ({@link MessagePort}s and {@link WebWorker}s). This class implements the {@link goog.messaging.MessageChannel} interface. This class can be used in conjunction with other communication on the port. It sets {@link goog.messaging.PortChannel.FLAG} to true on all messages it sends.

extends goog.messaging.AbstractChannel

Instance Method Summary
| `deliver_(?goog.events.Event e)` Delivers a message to the appropriate service handler. If this message isn't a GearsWorkerChannel message, it's ignored and passed on to other handlers.

`disposeInternal()`

Deletes or nulls out any references to COM objects, DOM nodes, or other disposable objects. Classes that extend {@code goog.Disposable} should override this method. Not reentrant. To avoid calling it twice, it must only be called from the subclass' {@code disposeInternal} method. Everywhere else the public {@code dispose} method must be used. For example:

    mypackage.MyClass = function() {
    goog.base(this);
    // Constructor logic specific to MyClass.
    ...
    };
    goog.inherits(mypackage.MyClass, goog.Disposable);

    mypackage.MyClass.prototype.disposeInternal = function() {
    goog.base(this, 'disposeInternal');
    // Dispose logic specific to MyClass.
    ...
    };

| `extractPorts_(?Array ports, (Object|string) message) ⇒ (Object|string)` Extracts all MessagePort objects from a message to be sent into an array. The message ports are replaced by placeholder objects that will be replaced with the ports again on the other side of the channel.
| `injectPorts_(?Array ports, (Object|string) message) ⇒ (Object|string)` Injects MessagePorts back into a message received from across the channel.
| `validateMessage_(?Object data) ⇒ boolean` Checks whether the message is invalid in some way.

Static Method Summary

`forEmbeddedWindow(!Window window, string peerOrigin, ?goog.Timer= opt_timer) ⇒ !goog.messaging.DeferredChannel`

Create a PortChannel that communicates with a window embedded in the current page (e.g. an iframe contentWindow). The code within the window should call {@link forGlobalWindow} to establish the connection. It's possible to use this channel in conjunction with other messages to the embedded window. However, only one PortChannel should be used for a given window at a time.

`forGlobalWindow(string peerOrigin) ⇒ !goog.messaging.MessageChannel`

Create a PortChannel that communicates with the document in which this window is embedded (e.g. within an iframe). The enclosing document should call {@link forEmbeddedWindow} to establish the connection. It's possible to use this channel in conjunction with other messages posted to the global window. However, only one PortChannel should be used for the global window at a time.