diff options
-rw-r--r-- | public/scripts/main.js | 25 | ||||
-rw-r--r-- | views/index.pug | 14 |
2 files changed, 29 insertions, 10 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)); }); diff --git a/views/index.pug b/views/index.pug index fc80e95..75ce696 100644 --- a/views/index.pug +++ b/views/index.pug @@ -9,13 +9,13 @@ block content h2.title Chat Window .containers pre#incoming.nes-container.with-title - form.form.nes-container.with-title + .form.nes-container.with-title .field label(for='outgoing') Message textarea#outgoing.nes-textarea - button(type=submit).nes-btn.is-primary Submit - form.form.nes-container.with-title - .field - label(for='user_id') Your friend's ID - input#user_id.nes-input - button(type=submit).nes-btn.is-primary Submit + button#message_form.nes-btn.is-primary(type=submit) Submit + .nes-container.with-title + .field + label(for='user_id') Your friend's ID + input#user_id.nes-input + button#user_id_form.nes-btn.is-primary(type=submit) Submit |