Client: add sendInit()
This commit is contained in:
parent
7ae0a01cf6
commit
c3c41a346c
|
|
@ -23,13 +23,12 @@ function openWebSocket() {
|
|||
function onOpen(evt) {
|
||||
console.log('Connected to ' + wsUri + '.');
|
||||
|
||||
let text = "Meow";
|
||||
console.log('Sending "' + text + '".');
|
||||
websocket.send(text);
|
||||
// Send init command containing chat ID and nickname
|
||||
sendInit();
|
||||
}
|
||||
|
||||
function onClose(evt) {
|
||||
console.log("Connection closed (code " + evt.code + "): ", evt);
|
||||
console.log("Connection closed (code " + evt.code + ").");
|
||||
}
|
||||
|
||||
function onMessage(evt) {
|
||||
|
|
@ -40,6 +39,21 @@ function onError(evt) {
|
|||
console.error('Connection error: ', evt);
|
||||
}
|
||||
|
||||
// Command senders
|
||||
function sendInit() {
|
||||
// Define command as JSON object
|
||||
let initObj = {
|
||||
action: "init",
|
||||
chat_id: "42",
|
||||
nickname: "binaryDiv"
|
||||
};
|
||||
|
||||
// Send command as JSON string
|
||||
let initJson = JSON.stringify(initObj);
|
||||
console.log('Sending init: ' + initJson);
|
||||
websocket.send(initJson);
|
||||
}
|
||||
|
||||
|
||||
// Run script after page is loaded
|
||||
$(function() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue