mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 01:42:50 +08:00
Initial commit: browser-based TeamSpeak client
React frontend + Node gateway + Rust connector (tsclientlib) providing connect, channel tree/switching, channel/server/private text chat, and voice with voice activation and output device selection.
This commit is contained in:
commit
b3e55a60b5
33 files changed
+7383
No files matched your search
@@ -0,0 +1,57 @@
|
||||
import { WebSocketServer, type WebSocket } from "ws";
|
||||
import { Ts3Connection, type Ts3ConnectOptions } from "./ts3/connection.js";
|
||||
|
||||
const PORT = Number(process.env.PORT ?? 8080);
|
||||
|
||||
const wss = new WebSocketServer({ port: PORT });
|
||||
|
||||
console.log(`Gateway listening on ws://localhost:${PORT}`);
|
||||
|
||||
wss.on("connection", (socket: WebSocket) => {
|
||||
let connection: Ts3Connection | undefined;
|
||||
|
||||
socket.on("message", async (raw) => {
|
||||
const msg = JSON.parse(raw.toString());
|
||||
|
||||
switch (msg.type) {
|
||||
case "connect": {
|
||||
const options: Ts3ConnectOptions = {
|
||||
host: msg.host,
|
||||
nickname: msg.nickname,
|
||||
};
|
||||
connection = new Ts3Connection(options);
|
||||
connection.onEvent((event) => socket.send(JSON.stringify(event)));
|
||||
await connection.connect();
|
||||
break;
|
||||
}
|
||||
case "switchChannel": {
|
||||
await connection?.switchChannel(msg.channelId);
|
||||
break;
|
||||
}
|
||||
case "sendChatMessage": {
|
||||
await connection?.sendChatMessage(msg.message);
|
||||
break;
|
||||
}
|
||||
case "sendServerMessage": {
|
||||
await connection?.sendServerMessage(msg.message);
|
||||
break;
|
||||
}
|
||||
case "sendPrivateMessage": {
|
||||
await connection?.sendPrivateMessage(msg.clientId, msg.message);
|
||||
break;
|
||||
}
|
||||
case "sendAudio": {
|
||||
await connection?.sendAudio(msg.pcm);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
socket.send(
|
||||
JSON.stringify({ type: "error", message: `Unknown message type: ${msg.type}` })
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("close", () => {
|
||||
connection?.disconnect();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user