Path: blob/trunk/third_party/closure/goog/messaging/portnetwork.js
2868 views
// Copyright 2011 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview An interface for classes that connect a collection of HTML516* message-passing entities ({@link MessagePort}s, {@link Worker}s, and17* {@link Window}s) and allow them to seamlessly communicate with one another.18*19* Conceptually, a PortNetwork is a collection of JS contexts, such as pages (in20* or outside of iframes) or web workers. Each context has a unique name, and21* each one can communicate with any of the others in the same network. This22* communication takes place through a {@link goog.messaging.PortChannel} that23* is retrieved via {#link goog.messaging.PortNetwork#dial}.24*25* One context (usually the main page) has a26* {@link goog.messaging.PortOperator}, which is in charge of connecting each27* context to each other context. All other contexts have28* {@link goog.messaging.PortCaller}s which connect to the operator.29*30*/3132goog.provide('goog.messaging.PortNetwork');33343536/**37* @interface38*/39goog.messaging.PortNetwork = function() {};404142/**43* Returns a message channel that communicates with the named context. If no44* such port exists, an error will either be thrown immediately or after a round45* trip with the operator, depending on whether this pool is the operator or a46* caller.47*48* If context A calls dial('B') and context B calls dial('A'), the two49* ports returned will be connected to one another.50*51* @param {string} name The name of the context to get.52* @return {goog.messaging.MessageChannel} The channel communicating with the53* given context. This is either a {@link goog.messaging.PortChannel} or a54* decorator around a PortChannel, so it's safe to send {@link MessagePorts}55* across it. This will be disposed along with the PortNetwork.56*/57goog.messaging.PortNetwork.prototype.dial = function(name) {};585960/**61* The name of the service exported by the operator for creating a connection62* between two callers.63*64* @type {string}65* @const66*/67goog.messaging.PortNetwork.REQUEST_CONNECTION_SERVICE = 'requestConnection';686970/**71* The name of the service exported by the callers for adding a connection to72* another context.73*74* @type {string}75* @const76*/77goog.messaging.PortNetwork.GRANT_CONNECTION_SERVICE = 'grantConnection';787980