Debian Codegraph @

closure-library/closure/goog/messaging/testdata/portchannel_worker.js

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