stash
This commit is contained in:
Vendored
+45
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
/**
|
||||
* webrtc page script
|
||||
*
|
||||
* Author: Peter Harpending <peterharpending@qpq.swiss>
|
||||
* Date: 2026-02-04
|
||||
* Copyright: Copyright (c) 2026 QPQ AG
|
||||
*
|
||||
* Reference: https://git.qpq.swiss/QPQ-AG/research-megadoc/src/commit/c7c4592d4b21ad120145ef63334471a1a7ec1e60/paste/2026-02/grok-webrtc.html
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
main();
|
||||
async function main() {
|
||||
// start websocket immediately
|
||||
let ws = new WebSocket('/ws/webrtc');
|
||||
// grab document elements
|
||||
let init = document.getElementById('init');
|
||||
let peers = document.getElementById('peers');
|
||||
let init_name = document.getElementById('init-name');
|
||||
let init_join = document.getElementById('init-join');
|
||||
// handle button click
|
||||
init_join.addEventListener('click', function () {
|
||||
handle_join(init, init_name, peers, ws);
|
||||
});
|
||||
// handle message from ws
|
||||
ws.onopen = function (e) { console.log('ws open:', e); };
|
||||
ws.onclose = function (e) { console.log('ws closed:', e); };
|
||||
ws.onerror = function (e) { console.error('ws error:', e); };
|
||||
ws.onmessage = function (e) { console.log('ws message', e); };
|
||||
}
|
||||
async function handle_join(init, init_name, peers, ws) {
|
||||
console.log('connecting...');
|
||||
let user_name = init_name.value.trim();
|
||||
console.log('username:', user_name);
|
||||
ws_send_json(ws, ['username', user_name]);
|
||||
init.hidden = true;
|
||||
peers.hidden = false;
|
||||
}
|
||||
function ws_send_json(ws, x) {
|
||||
let s = JSON.stringify(x, undefined, 4);
|
||||
console.log('sending:\n', s);
|
||||
ws.send(s);
|
||||
}
|
||||
//# sourceMappingURL=webrtc.js.map
|
||||
Reference in New Issue
Block a user