aboutsummaryrefslogtreecommitdiffhomepage
path: root/public
diff options
context:
space:
mode:
Diffstat (limited to 'public')
-rw-r--r--public/scripts/main.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/public/scripts/main.js b/public/scripts/main.js
index 45e3c79..d0d6073 100644
--- a/public/scripts/main.js
+++ b/public/scripts/main.js
@@ -4,12 +4,15 @@ 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));
+// Peer events
+peer.on('open', id => {
+ console.log('[LOG] Your ID is ' + id);
+ peer.on('data', data => console.log('[LOG] Received data ' + data));
+ peer.on('error', err => console.error(err));
+});
function connect(id) {
+ console.log('[LOG] Connecting to ' + id);
const connectionId = nanoid();
const conn = peer.connect(id, {label: connectionId});
console.log('[LOG] Your connection ID is ' + connectionId);
@@ -23,5 +26,5 @@ function connect(id) {
* Events after load
*/
$(document).ready(() => {
- $('#user_id_form').on('click', e => connect($('#user_id').text));
+ $('#user_id_form').on('click', e => connect($('#user_id').val()));
});