2024-09-30 02:11:58 +00:00
|
|
|
const ws = initChatService();
|
|
|
|
|
2024-09-30 01:49:30 +00:00
|
|
|
function initChatService() {
|
|
|
|
const ws = new WebSocket("ws://localhost:3000/chat-socket");
|
|
|
|
|
|
|
|
ws.onmessage = function (event) {
|
|
|
|
console.log(event);
|
|
|
|
};
|
|
|
|
ws.onopen = function (event) {
|
|
|
|
console.log("Opening the socket");
|
|
|
|
ws.send(JSON.stringify({ hello: "world" }));
|
|
|
|
};
|
|
|
|
ws.onclose = function (event) {
|
|
|
|
console.log("Closing the socket");
|
|
|
|
};
|
|
|
|
ws.onerror = function (event) {
|
|
|
|
console.log(event);
|
|
|
|
};
|
2024-09-30 02:11:58 +00:00
|
|
|
|
|
|
|
return ws;
|
2024-09-30 01:49:30 +00:00
|
|
|
}
|