portchannel_worker.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2010 The Closure Library Authors. All Rights Reserved.
  2. // Use of this source code is governed by the Apache License, Version 2.0.
  3. // See the COPYING file for details.
  4. /**
  5. * @fileoverview A web worker for integration testing the PortChannel class.
  6. *
  7. * @nocompile
  8. */
  9. self.CLOSURE_BASE_PATH = '../../';
  10. importScripts('../../bootstrap/webworkers.js');
  11. importScripts('../../base.js');
  12. // The provide is necessary to stop the jscompiler from thinking this is an
  13. // entry point and adding it into the manifest incorrectly.
  14. goog.provide('goog.messaging.testdata.portchannel_worker');
  15. goog.require('goog.messaging.PortChannel');
  16. function registerPing(channel) {
  17. channel.registerService(
  18. 'ping', function(msg) { channel.send('pong', msg); }, true);
  19. }
  20. function startListening() {
  21. var channel = new goog.messaging.PortChannel(self);
  22. registerPing(channel);
  23. channel.registerService('addPort', function(port) {
  24. port.start();
  25. registerPing(new goog.messaging.PortChannel(port));
  26. }, true);
  27. }
  28. startListening();
  29. // Signal to portchannel_test that the worker is ready.
  30. postMessage('loaded');