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 // Globals holding our encoder and decoder. We will never have more than one | 7 // Globals holding our encoder and decoder. We will never have more than one |
8 // Global variable that will be used to access this Nacl bridge. | 8 // Global variable that will be used to access this Nacl bridge. |
9 var whispernetNacl = null; | 9 var whispernetNacl = null; |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 whisperDecoder = new WhisperDecoder(audioParams.record, whispernetNacl); | 31 whisperDecoder = new WhisperDecoder(audioParams.record, whispernetNacl); |
32 whisperDecoder.setReceiveCallback(chrome.copresencePrivate.sendFound); | 32 whisperDecoder.setReceiveCallback(chrome.copresencePrivate.sendFound); |
33 whisperDecoder.onDetectBroadcast(chrome.copresencePrivate.sendDetect); | 33 whisperDecoder.onDetectBroadcast(chrome.copresencePrivate.sendDetect); |
34 | 34 |
35 chrome.copresencePrivate.sendInitialized(true); | 35 chrome.copresencePrivate.sendInitialized(true); |
36 } | 36 } |
37 | 37 |
38 /** | 38 /** |
39 * Sends a request to whispernet to encode a token. | 39 * Sends a request to whispernet to encode a token. |
40 * @param {string} token Token to encode. This needs to be a base64 string. | 40 * @param {string} token Token to encode. This needs to be a base64 string. |
| 41 * @param {boolean} audible Whether we should use encode audible samples. |
41 */ | 42 */ |
42 function encodeTokenRequest(token) { | 43 function encodeTokenRequest(token, audible) { |
43 if (whisperEncoder) { | 44 if (whisperEncoder) { |
44 whisperEncoder.encode(atob(token), true); | 45 whisperEncoder.encode(atob(token), audible, true); |
45 } else { | 46 } else { |
46 console.error('encodeTokenRequest: Whisper not initialized!'); | 47 console.error('encodeTokenRequest: Whisper not initialized!'); |
47 } | 48 } |
48 } | 49 } |
49 | 50 |
50 /** | 51 /** |
51 * Sends a request to whispernet to decode samples. | 52 * Sends a request to whispernet to decode samples. |
52 * @param {ArrayBuffer} samples Array of samples to decode. | 53 * @param {ArrayBuffer} samples Array of samples to decode. |
53 */ | 54 */ |
54 function decodeSamplesRequest(samples) { | 55 function decodeSamplesRequest(samples) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 */ | 96 */ |
96 function initWhispernet() { | 97 function initWhispernet() { |
97 console.log('init: Starting Nacl bridge.'); | 98 console.log('init: Starting Nacl bridge.'); |
98 // TODO(rkc): Figure out how to embed the .nmf and the .pexe into component | 99 // TODO(rkc): Figure out how to embed the .nmf and the .pexe into component |
99 // resources without having to rename them to .js. | 100 // resources without having to rename them to .js. |
100 whispernetNacl = new NaclBridge('whispernet_proxy.nmf.png', | 101 whispernetNacl = new NaclBridge('whispernet_proxy.nmf.png', |
101 onWhispernetLoaded); | 102 onWhispernetLoaded); |
102 } | 103 } |
103 | 104 |
104 window.addEventListener('DOMContentLoaded', initWhispernet); | 105 window.addEventListener('DOMContentLoaded', initWhispernet); |
OLD | NEW |