blob: 45e3c7921e8e0cab6eadea4bd6e95a19d248b423 (
plain) (
blame)
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
26
27
|
const $ = require('jquery');
const nanoid = require('nanoid');
const userId = nanoid();
const peer = new Peer(userId, {host: '127.0.0.1', port: 4242, path: '/', debug: 3});
// LOG
peer.on('open', id => console.log('[LOG] Your ID is ' + id));
peer.on('connection', data => console.log('[LOG] Received data ' + data));
peer.on('error', err => console.error(err));
function connect(id) {
const connectionId = nanoid();
const conn = peer.connect(id, {label: connectionId});
console.log('[LOG] Your connection ID is ' + connectionId);
conn.on('open', function () {
conn.send('hi!');
});
}
/**
* Events after load
*/
$(document).ready(() => {
$('#user_id_form').on('click', e => connect($('#user_id').text));
});
|