portnetwork.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. * @fileoverview An interface for classes that connect a collection of HTML5
  16. * message-passing entities ({@link MessagePort}s, {@link Worker}s, and
  17. * {@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 (in
  20. * or outside of iframes) or web workers. Each context has a unique name, and
  21. * each one can communicate with any of the others in the same network. This
  22. * communication takes place through a {@link goog.messaging.PortChannel} that
  23. * is retrieved via {#link goog.messaging.PortNetwork#dial}.
  24. *
  25. * One context (usually the main page) has a
  26. * {@link goog.messaging.PortOperator}, which is in charge of connecting each
  27. * context to each other context. All other contexts have
  28. * {@link goog.messaging.PortCaller}s which connect to the operator.
  29. *
  30. */
  31. goog.provide('goog.messaging.PortNetwork');
  32. /**
  33. * @interface
  34. */
  35. goog.messaging.PortNetwork = function() {};
  36. /**
  37. * Returns a message channel that communicates with the named context. If no
  38. * such port exists, an error will either be thrown immediately or after a round
  39. * trip with the operator, depending on whether this pool is the operator or a
  40. * caller.
  41. *
  42. * If context A calls dial('B') and context B calls dial('A'), the two
  43. * ports returned will be connected to one another.
  44. *
  45. * @param {string} name The name of the context to get.
  46. * @return {goog.messaging.MessageChannel} The channel communicating with the
  47. * given context. This is either a {@link goog.messaging.PortChannel} or a
  48. * decorator around a PortChannel, so it's safe to send {@link MessagePorts}
  49. * across it. This will be disposed along with the PortNetwork.
  50. */
  51. goog.messaging.PortNetwork.prototype.dial = function(name) {};
  52. /**
  53. * The name of the service exported by the operator for creating a connection
  54. * between two callers.
  55. *
  56. * @type {string}
  57. * @const
  58. */
  59. goog.messaging.PortNetwork.REQUEST_CONNECTION_SERVICE = 'requestConnection';
  60. /**
  61. * The name of the service exported by the callers for adding a connection to
  62. * another context.
  63. *
  64. * @type {string}
  65. * @const
  66. */
  67. goog.messaging.PortNetwork.GRANT_CONNECTION_SERVICE = 'grantConnection';