diff options
author | Marvin Borner | 2019-01-22 19:35:08 +0100 |
---|---|---|
committer | Marvin Borner | 2019-01-22 19:35:08 +0100 |
commit | 9eca06d0f79c24618a0813edd8ab31f1c6532f20 (patch) | |
tree | e9a2dfde7f095fd6dc6134a555737d9b91e44e59 /public | |
parent | 0f98a9fdeed9a1784a2ed5ea9aca3ebe0b37e19a (diff) |
Some events
Diffstat (limited to 'public')
-rw-r--r-- | public/scripts/main.js | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/public/scripts/main.js b/public/scripts/main.js index 409580d..45e3c79 100644 --- a/public/scripts/main.js +++ b/public/scripts/main.js @@ -1,8 +1,27 @@ +const $ = require('jquery'); const nanoid = require('nanoid'); const userId = nanoid(); -const peer = new Peer(userId, {host: '127.0.0.1', port: 4242, path: '/'}); +const peer = new Peer(userId, {host: '127.0.0.1', port: 4242, path: '/', debug: 3}); -peer.on('open', id => { - console.log('[LOG] Your ID is ' + id) +// 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)); }); |