OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 // Global holding our NaclBridge. | 7 // Global holding our NaclBridge. |
8 var whispernetNacl = null; | 8 var whispernetNacl = null; |
9 | 9 |
10 // Encoders and decoders for each client. | 10 // Encoders and decoders for each client. |
11 var whisperEncoders = {}; | 11 var whisperEncoders = {}; |
12 var whisperDecoders = {}; | 12 var whisperDecoders = {}; |
13 | 13 |
14 /** | 14 /** |
15 * Initialize the whispernet encoder and decoder. | 15 * Initialize the whispernet encoder and decoder. |
16 * Call this before any other functions. | 16 * Call this before any other functions. |
17 * @param {string} clientId A string identifying the requester. | 17 * @param {string} clientId A string identifying the requester. |
18 * @param {Object} audioParams Audio parameters for token encoding and decoding. | 18 * @param {Object} audioParams Audio parameters for token encoding and decoding. |
19 */ | 19 */ |
20 function audioConfig(clientId, audioParams) { | 20 function audioConfig(clientId, audioParams) { |
21 if (!whispernetNacl) { | 21 if (!whispernetNacl) { |
22 chrome.copresencePrivate.sendInitialized(false); | 22 chrome.copresencePrivate.sendInitialized(false); |
23 return; | 23 return; |
24 } | 24 } |
25 | 25 |
26 console.log('Configuring encoder and decoder!'); | 26 console.log('Configuring encoder and decoder for client ' + clientId); |
27 whisperEncoders[clientId] = | 27 whisperEncoders[clientId] = |
28 new WhisperEncoder(audioParams.paramData, whispernetNacl, clientId); | 28 new WhisperEncoder(audioParams.paramData, whispernetNacl, clientId); |
29 whisperDecoders[clientId] = | 29 whisperDecoders[clientId] = |
30 new WhisperDecoder(audioParams.paramData, whispernetNacl, clientId); | 30 new WhisperDecoder(audioParams.paramData, whispernetNacl, clientId); |
31 } | 31 } |
32 | 32 |
33 /** | 33 /** |
34 * Sends a request to whispernet to encode a token. | 34 * Sends a request to whispernet to encode a token. |
35 * @param {string} clientId A string identifying the requester. | 35 * @param {string} clientId A string identifying the requester. |
36 * @param {Object} params Encode token parameters object. | 36 * @param {Object} params Encode token parameters object. |
37 */ | 37 */ |
38 function encodeTokenRequest(clientId, params) { | 38 function encodeTokenRequest(clientId, params) { |
39 if (whisperEncoders[clientId]) { | 39 if (whisperEncoders[clientId]) { |
40 whisperEncoders[clientId].encode(params); | 40 whisperEncoders[clientId].encode(params); |
41 } else { | 41 } else { |
42 console.error('encodeTokenRequest: Whisper not initialized!'); | 42 console.error('encodeTokenRequest: Whisper not initialized for client ' + |
| 43 clientId); |
43 } | 44 } |
44 } | 45 } |
45 | 46 |
46 /** | 47 /** |
47 * Sends a request to whispernet to decode samples. | 48 * Sends a request to whispernet to decode samples. |
48 * @param {string} clientId A string identifying the requester. | 49 * @param {string} clientId A string identifying the requester. |
49 * @param {Object} params Process samples parameters object. | 50 * @param {Object} params Process samples parameters object. |
50 */ | 51 */ |
51 function decodeSamplesRequest(clientId, params) { | 52 function decodeSamplesRequest(clientId, params) { |
52 if (whisperDecoders[clientId]) { | 53 if (whisperDecoders[clientId]) { |
53 whisperDecoders[clientId].processSamples(params); | 54 whisperDecoders[clientId].processSamples(params); |
54 } else { | 55 } else { |
55 console.error('decodeSamplesRequest: Whisper not initialized!'); | 56 console.error('decodeSamplesRequest: Whisper not initialized for client ' + |
| 57 clientId); |
56 } | 58 } |
57 } | 59 } |
58 | 60 |
59 /** | 61 /** |
60 * Initialize our listeners and signal that the extension is loaded. | 62 * Initialize our listeners and signal that the extension is loaded. |
61 */ | 63 */ |
62 function onWhispernetLoaded() { | 64 function onWhispernetLoaded() { |
63 console.log('init: Nacl ready!'); | 65 console.log('init: Nacl ready!'); |
64 | 66 |
65 // Setup all the listeners for the private API. | 67 // Setup all the listeners for the private API. |
(...skipping 13 matching lines...) Expand all Loading... |
79 */ | 81 */ |
80 function initWhispernet() { | 82 function initWhispernet() { |
81 console.log('init: Starting Nacl bridge.'); | 83 console.log('init: Starting Nacl bridge.'); |
82 // TODO(rkc): Figure out how to embed the .nmf and the .pexe into component | 84 // TODO(rkc): Figure out how to embed the .nmf and the .pexe into component |
83 // resources without having to rename them to .js. | 85 // resources without having to rename them to .js. |
84 whispernetNacl = new NaclBridge('whispernet_proxy.nmf.png', | 86 whispernetNacl = new NaclBridge('whispernet_proxy.nmf.png', |
85 onWhispernetLoaded); | 87 onWhispernetLoaded); |
86 } | 88 } |
87 | 89 |
88 window.addEventListener('DOMContentLoaded', initWhispernet); | 90 window.addEventListener('DOMContentLoaded', initWhispernet); |
OLD | NEW |