-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
38 lines (33 loc) · 1.25 KB
/
main.js
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
37
38
import ConnectionManager from './src/networking/ConnectionManager.js';
import { PositionPacket } from "./src/networking/Packets.js";
const connection = new ConnectionManager();
connection.initialize();
document.getElementById('send-btn').addEventListener('click', () => {
const message = document.getElementById('message').value.trim();
document.getElementById('message').value = '';
if (message) {
if (message.startsWith('§')) {
connection.sendAlert(message.substring(1));
} else {
connection.sendMessage(message);
appendMessage('Sent: ' + message);
}
}
});
document.getElementById('connect-btn').addEventListener('click', () => {
const destPeerId = document.getElementById('peer-id-input').value.trim();
if (destPeerId) {
connection.connectToPeer(destPeerId);
} else {
alert('Enter destination peer ID');
}
});
function appendMessage(message) {
const messagesDiv = document.getElementById('messages');
const messageElem = document.createElement('div');
messageElem.textContent = message;
messagesDiv.appendChild(messageElem);
}
document.addEventListener('mousemove', event => {
connection.broadcastPacket(new PositionPacket(event.x, event.y))
});