goog.net.WebChannel
Provided By | |
---|---|
All Extended Interfaces | |
All Known Implementations |
A WebChannel represents a logical bi-directional channel over which the
client communicates with a remote server that holds the other endpoint
of the channel. A WebChannel is always created in the context of a shared
WebChannelTransport
instance. It is up to the underlying client-side
and server-side implementations to decide how or when multiplexing is
to be enabled.
Instance Methods
this.close() → void
void
Close the WebChannel.
This is a full close (shutdown) with no guarantee of FIFO delivery in respect to any in-flight messages sent to the server.
If you need such a guarantee, see the Half the halfClose() method.
this.dispatchEvent( e ) → boolean
boolean
Dispatches an event (or event like object) and calls all listeners listening for events of this type. The type of the event is decided by the type property on the event object.
If any of the listeners returns false OR calls preventDefault then this function will return false. If one of the capture listeners calls stopPropagation, then the bubble listeners won't fire.
Specified by | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Returns |
|
this.fireListeners<EVENTOBJ>( type, capture, eventObject ) → boolean
boolean
Fires all registered listeners in this listenable for the given type and capture mode, passing them the given eventObject. This does not perform actual capture/bubble. Only implementors of the interface should be using this.
Specified by | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
| ||||||||||||
Returns |
|
this.getListener<SCOPE, EVENTOBJ>( type, listener, capture, opt_listenerScope ) → (goog.events.ListenableKey|null)
(goog.events.ListenableKey|null)
Gets the goog.events.ListenableKey for the event or null if no such listener is in use.
Specified by | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
| ||||||||||||||||
Returns |
|
this.getListeners<EVENTOBJ>( type, capture ) → Array<goog.events.ListenableKey>
Array<goog.events.ListenableKey>
Gets all listeners in this listenable for the given type and capture mode.
Specified by | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
| ||||||||
Returns |
|
this.getParentEventTarget() → (goog.events.Listenable|null)
(goog.events.Listenable|null)
Returns the parent of this event target to use for capture/bubble mechanism.
NOTE(chrishenry): The name reflects the original implementation of
custom event target (goog.events.EventTarget
). We decided
that changing the name is not worth it.
Specified by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getRuntimeProperties() → goog.net.WebChannel.RuntimeProperties
goog.net.WebChannel.RuntimeProperties
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.halfClose() → void
void
Half-close the WebChannel.
Half-close semantics:
- delivered as a regular message in FIFO programming order
- the server is expected to return a half-close too (with or without application involved), which will trigger a full close (shutdown) on the client side
- for now, the half-close event defined for server-initiated half-close is not exposed to the client application
- a client-side half-close may be triggered internally when the client receives a half-close from the server; and the client is expected to do a full close after the half-close is acked and delivered on the server-side.
- Full close is always a forced one. See the close() method.
New messages sent after halfClose() will be dropped.
NOTE: This is not yet implemented, and will throw an exception if called.
this.hasListener<EVENTOBJ>( opt_type, opt_capture ) → boolean
boolean
Whether there is any active listeners matching the specified signature. If either the type or capture parameters are unspecified, the function will match on the remaining criteria.
Specified by | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
| ||||||||
Returns |
|
this.listen<SCOPE, EVENTOBJ>( type, listener, opt_useCapture, opt_listenerScope ) → goog.events.ListenableKey
goog.events.ListenableKey
Adds an event listener. A listener can only be added once to an object and if it is added again the key for the listener is returned. Note that if the existing listener is a one-off listener (registered via listenOnce), it will no longer be a one-off listener after a call to listen().
Specified by | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
| ||||||||||||||||
Returns |
|
this.listenOnce<SCOPE, EVENTOBJ>( type, listener, opt_useCapture, opt_listenerScope ) → goog.events.ListenableKey
goog.events.ListenableKey
Adds an event listener that is removed automatically after the listener fired once.
If an existing listener already exists, listenOnce will do nothing. In particular, if the listener was previously registered via listen(), listenOnce() will not turn the listener into a one-off listener. Similarly, if there is already an existing one-off listener, listenOnce does not modify the listeners (it is still a once listener).
Specified by | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
| ||||||||||||||||
Returns |
|
this.open() → void
void
Open the WebChannel against the URI specified in the constructor.
this.removeAllListeners( opt_type ) → number
number
Removes all listeners from this listenable. If type is specified, it will only remove listeners of the particular type. otherwise all registered listeners will be removed.
Specified by | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Returns |
|
this.send( message ) → void
void
Sends a message to the server that maintains the other endpoint of the WebChannel.
O-RTT behavior:
- messages sent before open() is called will always be delivered as part of the handshake, i.e. with 0-RTT
- messages sent after open() is called but before the OPEN event is received will be delivered as part of the handshake if send() is called from the same execution context as open().
- otherwise, those messages will be buffered till the handshake is completed (which will fire the OPEN event).
Parameters |
|
---|
this.unlisten<SCOPE, EVENTOBJ>( type, listener, opt_useCapture, opt_listenerScope ) → boolean
boolean
Removes an event listener which was added with listen() or listenOnce().
Specified by | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
| ||||||||||||||||
Returns |
|
this.unlistenByKey( key ) → boolean
boolean
Removes an event listener which was added with listen() by the key returned by listen().
Specified by | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Returns |
|
Properties
Types that are allowed as message data.
Note that JS objects (sent by the client) can only have string encoded values due to the limitation of the current wire protocol.
Unicode strings (sent by the server) may or may not need be escaped, as decided by the server.
WebChannel.X_CLIENT_PROTOCOL → string
string
A request header to indicate to the server the messaging protocol each HTTP message is speaking.
WebChannel.X_CLIENT_PROTOCOL_WEB_CHANNEL → string
string
The value for x-client-protocol when the messaging protocol is WebChannel.
WebChannel.X_CLIENT_WIRE_PROTOCOL → string
string
A response header for the server to signal the wire-protocol that the browser establishes with the server (or proxy), e.g. "spdy" (aka http/2) "quic". This information avoids the need to use private APIs to decide if HTTP requests are multiplexed etc.
WebChannel.X_HTTP_INITIAL_RESPONSE → string
string
A response header for the server to send back any initial response data as a header to avoid any possible buffering by an intermediary, which may be undesired during the handshake.
WebChannel.X_HTTP_SESSION_ID → string
string
A response header for the server to send back the HTTP session id as part of the initial handshake. The value of the HTTP session id is opaque to the WebChannel protocol.
WebChannel.X_WEBCHANNEL_CLIENT_PROFILE → string
string
A request header for specifying the client profile in order to apply customized config params on the server side, e.g. timeouts.
WebChannel.X_WEBCHANNEL_CONTENT_TYPE → string
string
A request header for specifying the content-type of WebChannel messages, e.g. application-defined JSON encoding styles. Currently this header is sent by the client via initMessageHeaders when the channel is opened.