goog.messaging.PortChannel
Classgoog.messaging.PortChannel
> goog.messaging.AbstractChannel
> goog.Disposable
goog.messaging.PortChannel(underlyingPort)
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.
underlyingPort
{!MessagePort
|!WebWorker
}
.FLAG
{string
}The flag added to messages that are sent by a PortChannel, and are meant to be handled by one on the other side.
.addOnDisposeCallback(callback, opt_scope)
Inherited from goog.Disposable
.
Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.
callback
{!Function
}
opt_scope
{Object
=}
.connect()
Inherited from goog.messaging.AbstractChannel
.
Immediately calls opt_connectCb if given, and is otherwise a no-op. If subclasses have configuration that needs to happen before the channel is connected, they should override this and {@link #isConnected}.
.creationStack
{string
}Inherited from goog.Disposable
.
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
.decodePayload(serviceName, payload, objectPayload)
[protected]Inherited from goog.messaging.AbstractChannel
.
Converts the message payload into the format expected by the registered service (either JSON or string).
serviceName
{string
}
payload
{string
|!Object
}
objectPayload
{boolean
}
string
|Object
}
.deliver(serviceName, payload)
[protected]Inherited from goog.messaging.AbstractChannel
.
Delivers a message to the appropriate service. This is meant to be called by subclasses when they receive messages. This method takes into account both explicitly-registered and default services, as well as making sure that JSON payloads are decoded when necessary. If the subclass is capable of passing objects as payloads, those objects can be passed in to this method directly. Otherwise, the (potentially JSON-encoded) strings should be passed in.
serviceName
{string
}
payload
{string
|!Object
}
.dispose()
Inherited from goog.Disposable
.
Disposes of the object. If the object hasn't already been disposed of, calls {@link #disposeInternal}. Classes that extend {@code goog.Disposable} should override {@link #disposeInternal} in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.
void
}
.disposeInternal()
[protected]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. ... };
.forEmbeddedWindow(window, peerOrigin, opt_timer)
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.
window
{!Window
}
peerOrigin
{string
}
opt_timer
{goog.Timer
=}
goog.messaging.DeferredChannel
}
.forGlobalWindow(peerOrigin)
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.
peerOrigin
{string
}
goog.messaging.MessageChannel
}
.getDisposed
[deprecated]Deprecated. Use {@link #isDisposed} instead.
Inherited from goog.Disposable
.
boolean
}
.getService(serviceName, payload)
[protected]Inherited from goog.messaging.AbstractChannel
.
Find the service object for a given service name. If there's no service explicitly registered, but there is a default service, a service object is constructed for it.
serviceName
{string
}
payload
{string
|!Object
}
callback
: function
((string
|!Object
)), objectPayload
: boolean
}}
.isConnected()
Inherited from goog.messaging.AbstractChannel
.
Always returns true. If subclasses have configuration that needs to happen before the channel is connected, they should override this and {@link #connect}.
.isDisposed()
Inherited from goog.Disposable
.
boolean
}
.logger
[protected] {goog.debug.Logger
}Logger for this class.
.registerDefaultService()
Inherited from goog.messaging.AbstractChannel
.
.registerDisposable(disposable)
Inherited from goog.Disposable
.
Associates a disposable object with this object so that they will be disposed together.
disposable
{goog.disposable.IDisposable
}
.registerService()
Inherited from goog.messaging.AbstractChannel
.
.send(serviceName, payload)
Sends a message over the channel. As an addition to the basic MessageChannel send API, PortChannels can send objects that contain MessagePorts. Note that only plain Objects and Arrays, not their subclasses, can contain MessagePorts. As per {@link http://www.w3.org/TR/html5/comms.html#clone-a-port}, once a port is copied to be sent across a channel, the original port will cease being able to send or receive messages.
serviceName
{string
}
payload
{string
|!Object
|!MessagePort
}