blob: 8430851562129a4d3e481e9011c85a2f86454018 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
import Backdrop from './modules/ui/backdrop.js';
import * as signalR from "@aspnet/signalr";
let backdrop = new Backdrop('menu', 'front-layer', 'show-menu');
backdrop.register();
const connection = new signalR.HubConnectionBuilder()
.withUrl("http://89.183.31.151:5000/chatHub")
.configureLogging(signalR.LogLevel.Information)
.build();
connection.on('ReceiveMessage', (user, message) => {
let msg = message.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
let encodedMsg = user + " says " + msg;
let li = document.createElement("li");
li.textContent = encodedMsg;
document.getElementById('message-list').appendChild(li);
});
document.getElementById('send-button').addEventListener('click', () => {
let user = document.getElementById("user-input").value;
let message = document.getElementById("message-input").value;
connection.invoke("SendMessage", user, message).catch(function (err) {
return console.error(err.toString());
});
event.preventDefault();
});
connection.start().catch(err => console.error(err.toString()));
|