ExtinctionOnline/static/js/websocket.js

19 lines
517 B
JavaScript
Raw Normal View History

2022-11-13 21:30:01 +09:00
"use strict";
2022-11-04 22:05:08 +09:00
// WebSocket 接続を作成
const socket = new WebSocket('ws://localhost:1234');
// 接続が開いたときのイベント
socket.addEventListener('open', function (event) {
});
// メッセージの待ち受け
socket.addEventListener('message', function (event) {
let obj = JSON.parse(event.data);
2022-11-13 21:30:01 +09:00
console.log('Server>', obj);
2022-11-04 22:05:08 +09:00
if (obj.messageType == "SYSTEM") {
onSystemMessage(obj);
2022-11-13 21:30:01 +09:00
} else if (obj.messageType == "GAME") {
2022-11-04 22:05:08 +09:00
controller.onGameMessage(obj);
}
});