goog.messaging.PortChannel
Provided By | |
---|---|
Extends | |
All Implemented Interfaces |
A wrapper for several types of HTML5 message-passing entities
(MessagePort
s and Worker
s). This class implements the
goog.messaging.MessageChannel
interface.
This class can be used in conjunction with other communication on the port.
It sets goog.messaging.PortChannel.FLAG
to true on all messages it
sends.
new PortChannel( underlyingPort )
Parameters |
|
---|
Instance Methods
this.addOnDisposeCallback<T>( callback, opt_scope ) → void
void
Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added. If a callback is added to an already disposed Disposable, it will be called immediately.
Defined by | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.connect( opt_connectCb ) → void
void
Initiates the channel connection. When this method is called, all the information needed to connect the channel has to be available.
Implementers should only require this method to be called if the channel needs to be configured in some way between when it's created and when it becomes active. Otherwise, the channel should be immediately active and this method should do nothing but immediately call opt_connectCb.
Overrides | |||||
---|---|---|---|---|---|
Specified by | |||||
Parameters |
|
Converts the message payload into the format expected by the registered service (either JSON or string).
Defined by | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
| ||||||||||||
Returns |
|
this.deliver( serviceName, payload ) → void
void
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.
Defined by | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.dispose() → ?
?
Disposes of the object and its resources.
Overrides | ||
---|---|---|
Specified by | ||
Parameters | None. | |
Returns |
|
this.disposeInternal() → void
void
Performs appropriate cleanup. See description of goog.disposable.IDisposable
for examples. Classes that extend goog.Disposable
should override this
method. Not reentrant. To avoid calling it twice, it must only be called from
the subclass' disposeInternal
method. Everywhere else the public dispose
method must be used. For example:
mypackage.MyClass = function() { mypackage.MyClass.base(this, 'constructor'); // Constructor logic specific to MyClass. ... }; goog.inherits(mypackage.MyClass, goog.Disposable); mypackage.MyClass.prototype.disposeInternal = function() { // Dispose logic specific to MyClass. ... // Call superclass's disposeInternal at the end of the subclass's, like // in C++, to avoid hard-to-catch issues. mypackage.MyClass.base(this, 'disposeInternal'); };
Overrides | |
---|---|
Parameters | None. |
this.getDisposed() → boolean
boolean
warning Deprecated | Use |
---|
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
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.
Defined by | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
| ||||||||
Returns |
|
this.isConnected() → boolean
boolean
Gets whether the channel is connected.
If #connect
is not required for this class, this should always return
true. Otherwise, this should return true by the time the callback passed to
#connect
has been called and always after that.
Overrides | |||
---|---|---|---|
Specified by | |||
Parameters | None. | ||
Returns |
|
this.isDisposed() → boolean
boolean
Overrides | |||
---|---|---|---|
Specified by | |||
Parameters | None. | ||
Returns |
|
this.registerDefaultService( callback ) → void
void
Registers a service to be called when a message is received that doesn't match any other services.
Overrides | |||||
---|---|---|---|---|---|
Specified by | |||||
Parameters |
|
this.registerDisposable( disposable ) → void
void
Associates a disposable object with this object so that they will be disposed together.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.registerService( serviceName, callback, opt_objectPayload ) → void
void
Registers a service to be called when a message is received.
Implementers shouldn't impose any restrictions on the service names that may
be registered. If some services are needed as control codes,
goog.messaging.MultiMessageChannel
can be used to safely split the
channel into "public" and "control" virtual channels.
Overrides | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||
Parameters |
|
this.send( serviceName, payload ) → void
void
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 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.
Overrides | |||||||||
---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||
Parameters |
|
Instance Properties
this.creationStack → (string|undefined)
(string|undefined)
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
this.logger → (goog.log.Logger|null)
(goog.log.Logger|null)
Static Functions
PortChannel.forEmbeddedWindow( peerWindow, peerOrigin, opt_timer ) → goog.messaging.DeferredChannel
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
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.
Parameters |
| ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
|
PortChannel.forGlobalWindow( peerOrigin ) → goog.messaging.MessageChannel
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
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.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
Static Properties
PortChannel.FLAG → string
string
The flag added to messages that are sent by a PortChannel, and are meant to be handled by one on the other side.