refactor quotes

This commit is contained in:
Lexi / Zoe 2018-11-24 03:45:12 +01:00
parent 733a537f58
commit fd6a40cb0d
2 changed files with 18 additions and 16 deletions

View file

@ -1,5 +1,5 @@
// Constants and variables
//const wsUri = "ws://localhost:32715";
// const wsUri = "ws://localhost:32715";
const wsUri = "wss://chat.glitch-in.space:443/ws/";
let websocket;
@ -21,7 +21,7 @@ function openWebSocket() {
// WebSocket event handlers
function onOpen(evt) {
console.log('Connected to ' + wsUri + '.');
console.log("Connected to " + wsUri + ".");
// Send init command containing chat ID and nickname
sendInit();
@ -32,12 +32,12 @@ function onClose(evt) {
}
function onMessage(evt) {
console.log('Received: "' + evt.data + '".');
console.log("Received: " + evt.data);
parseMessage(evt.data);
}
function onError(evt) {
console.error('Connection error: ', evt);
console.error("Connection error: ", evt);
}
// Command senders
@ -51,7 +51,7 @@ function sendInit() {
// Send command as JSON string
let initJson = JSON.stringify(initObj);
console.log('Sending init: ' + initJson);
console.log("Sending init: " + initJson);
websocket.send(initJson);
}
@ -61,26 +61,26 @@ function parseMessage(msgString) {
let msg = JSON.parse(msgString);
switch (msg.type) {
// Response to 'init' command
case 'init':
// Response to "init" command
case "init":
// TODO
console.log('Got init response: ', msg);
console.log("Got init response: ", msg);
break;
// Incoming chat message
case 'message':
case "message":
// TODO
console.log('Got message event: from "' + msg.from + '", text "' + msg.text + '"');
console.log("Got message event: from '" + msg.from + "', text '" + msg.text + "'");
break;
// TODO Topic change, user join/leave, error, ...
default:
console.error('Unknown message type: "' + msg.type + '"');
console.error("Unknown message type '" + msg.type + "'");
}
}
catch (e) {
console.error('Error parsing message JSON: ' + e.message);
console.error("Error parsing message JSON: " + e.message);
}
}