mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-02 17:32:50 +08:00
Persist client identity across sessions
Previously every connect generated a fresh tsclientlib identity, so the server saw a new client UID each session. The connector now accepts a saved identity via --identity and always reports the one actually used (freshly generated or reused) back in the "connected" event; the frontend round-trips it through localStorage so reconnecting keeps the same UID. Verified end-to-end against the real test server: two separate connects with the identity carried over produced byte-identical identity blobs.
This commit is contained in:
1 parent
249687d98a
commit
7217bc146a
4 files changed
+31
-2
No files matched your search
@@ -71,6 +71,7 @@ wss.on("connection", (socket: WebSocket) => {
|
||||
serverPassword: msg.serverPassword,
|
||||
channelPassword: msg.channelPassword,
|
||||
defaultChannel: msg.defaultChannel,
|
||||
identity: msg.identity,
|
||||
};
|
||||
connection = new Ts3Connection(options);
|
||||
connection.onEvent((event) => socket.send(JSON.stringify(event)));
|
||||
|
||||
@@ -54,6 +54,7 @@ export type Ts3ConnectionEvent =
|
||||
serverVersion: string;
|
||||
serverLicense: string;
|
||||
serverBannerUrl: string;
|
||||
identity: string;
|
||||
}
|
||||
| { type: "channels"; channels: ChannelInfo[]; clients: ClientInfo[] }
|
||||
| { type: "chatMessage"; from: string; message: string }
|
||||
@@ -72,6 +73,9 @@ export interface Ts3ConnectOptions {
|
||||
serverPassword?: string;
|
||||
channelPassword?: string;
|
||||
defaultChannel?: string;
|
||||
/** Previously-issued identity (from a prior "connected" event) to keep
|
||||
* the same client UID across sessions. Omit to get a freshly generated one. */
|
||||
identity?: string;
|
||||
}
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
@@ -102,6 +106,7 @@ export class Ts3Connection {
|
||||
if (this.options.serverPassword) args.push("--server-password", this.options.serverPassword);
|
||||
if (this.options.channelPassword) args.push("--channel-password", this.options.channelPassword);
|
||||
if (this.options.defaultChannel) args.push("--default-channel", this.options.defaultChannel);
|
||||
if (this.options.identity) args.push("--identity", this.options.identity);
|
||||
this.child = spawn(CONNECTOR_BIN, args);
|
||||
|
||||
createInterface({ input: this.child.stdout }).on("line", (line) => {
|
||||
@@ -139,6 +144,7 @@ export class Ts3Connection {
|
||||
server_version: string;
|
||||
server_license: string;
|
||||
server_banner_url: string;
|
||||
identity: string;
|
||||
}
|
||||
| { type: "channels"; channels: RawChannelInfo[]; clients: RawClientInfo[] }
|
||||
| { type: "chatMessage"; from: string; message: string }
|
||||
@@ -160,6 +166,7 @@ export class Ts3Connection {
|
||||
serverVersion: event.server_version,
|
||||
serverLicense: event.server_license,
|
||||
serverBannerUrl: event.server_banner_url,
|
||||
identity: event.identity,
|
||||
});
|
||||
} else if (event.type === "channels") {
|
||||
this.emit({
|
||||
|
||||
Reference in new issue
Block a user