| 1 |
// Copyright 2011 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
/** |
| 16 |
* @fileoverview An interface for classes that connect a collection of HTML5 |
| 17 |
* message-passing entities ({@link MessagePort}s, {@link Worker}s, and |
| 18 |
* {@link Window}s) and allow them to seamlessly communicate with one another. |
| 19 |
* |
| 20 |
* Conceptually, a PortNetwork is a collection of JS contexts, such as pages (in |
| 21 |
* or outside of iframes) or web workers. Each context has a unique name, and |
| 22 |
* each one can communicate with any of the others in the same network. This |
| 23 |
* communication takes place through a {@link goog.messaging.PortChannel} that |
| 24 |
* is retrieved via {#link goog.messaging.PortNetwork#dial}. |
| 25 |
* |
| 26 |
* One context (usually the main page) has a |
| 27 |
* {@link goog.messaging.PortOperator}, which is in charge of connecting each |
| 28 |
* context to each other context. All other contexts have |
| 29 |
* {@link goog.messaging.PortCaller}s which connect to the operator. |
| 30 |
* |
| 31 |
*/ |
| 32 |
|
| 33 |
goog.provide('goog.messaging.PortNetwork'); |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
/** |
| 38 |
* @interface |
| 39 |
*/ |
| 40 |
goog.messaging.PortNetwork = function() {}; |
| 41 |
|
| 42 |
|
| 43 |
/** |
| 44 |
* Returns a message channel that communicates with the named context. If no |
| 45 |
* such port exists, an error will either be thrown immediately or after a round |
| 46 |
* trip with the operator, depending on whether this pool is the operator or a |
| 47 |
* caller. |
| 48 |
* |
| 49 |
* If context A calls dial('B') and context B calls dial('A'), the two |
| 50 |
* ports returned will be connected to one another. |
| 51 |
* |
| 52 |
* @param {string} name The name of the context to get. |
| 53 |
* @return {goog.messaging.MessageChannel} The channel communicating with the |
| 54 |
* given context. This is either a {@link goog.messaging.PortChannel} or a |
| 55 |
* decorator around a PortChannel, so it's safe to send {@link MessagePorts} |
| 56 |
* across it. This will be disposed along with the PortNetwork. |
| 57 |
*/ |
| 58 |
goog.messaging.PortNetwork.prototype.dial = function(name) {}; |
| 59 |
|
| 60 |
|
| 61 |
/** |
| 62 |
* The name of the service exported by the operator for creating a connection |
| 63 |
* between two callers. |
| 64 |
* |
| 65 |
* @type {string} |
| 66 |
* @const |
| 67 |
*/ |
| 68 |
goog.messaging.PortNetwork.REQUEST_CONNECTION_SERVICE = 'requestConnection'; |
| 69 |
|
| 70 |
|
| 71 |
/** |
| 72 |
* The name of the service exported by the callers for adding a connection to |
| 73 |
* another context. |
| 74 |
* |
| 75 |
* @type {string} |
| 76 |
* @const |
| 77 |
*/ |
| 78 |
goog.messaging.PortNetwork.GRANT_CONNECTION_SERVICE = 'grantConnection'; |