Sha256: 31e053086389dd044a71ee6b26f998249f22ab1651a4d1c0968157d766cea9f7
Contents?: true
Size: 640 Bytes
Versions: 15
Compression:
Stored size: 640 Bytes
Contents
var url = new URL('/server/connect', window.location.href); url.protocol = url.protocol.replace('http', 'ws'); console.log("Connecting to server", url); var server = new WebSocket(url.href); console.log("Connected to", server); server.onopen = function(event) { chat.onkeypress = function(event) { if (event.keyCode == 13) { server.send(JSON.stringify({text: chat.value})); chat.value = ""; } } }; server.onmessage = function(event) { console.log("Got message", event); var message = JSON.parse(event.data); var pre = document.createElement('pre'); pre.innerText = message.text; response.appendChild(pre); };
Version data entries
15 entries across 15 versions & 1 rubygems