-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
25 lines (19 loc) · 1.02 KB
/
client.js
File metadata and controls
25 lines (19 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const { OTManager, arrayToChoiceBits } = require('./index');
const ot = new OTManager(false, false);
ot.connect("127.0.0.1:12345");
console.log('is connected:', ot.isConnected());
console.log('is server:', ot.isServer());
console.time('ot example');
// choices are bits encoded in bytes, so to have 2 choices we need 1 byte with 2 bits set as choices (little endian)
const receivedData = ot.requestData(...arrayToChoiceBits([0, 1]));
console.timeEnd('ot example');
console.log(receivedData);
console.log('client responds now');
const clientData = [
0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0,
0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1,
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1,
];
ot.respondWithData(Uint8Array.from(clientData))
console.log('client responded with data');