mirror of
https://github.com/Rolands-Laucis/Socio.git
synced 2026-05-15 14:15:57 -06:00
identify self recon case
This commit is contained in:
parent
9235ba5dad
commit
d328473b6d
6 changed files with 16 additions and 9 deletions
|
|
@ -154,8 +154,9 @@ export class SocioClient extends LogHandler {
|
||||||
this.#client_id = data as C_CON_data;//should just be a string
|
this.#client_id = data as C_CON_data;//should just be a string
|
||||||
this.#latency = (new Date()).getTime() - this.#latency;
|
this.#latency = (new Date()).getTime() - this.#latency;
|
||||||
|
|
||||||
|
let successful_recon = false;
|
||||||
if (this.config.persistent) {
|
if (this.config.persistent) {
|
||||||
await this.#TryReconnect(); //try to reconnect with existing token in local storage
|
successful_recon = await this.#TryReconnect(); //try to reconnect with existing token in local storage
|
||||||
await this.#GetReconToken(); //get new recon token and push to local storage
|
await this.#GetReconToken(); //get new recon token and push to local storage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -171,7 +172,7 @@ export class SocioClient extends LogHandler {
|
||||||
//persistance would restore the old name, so no need to announce again.
|
//persistance would restore the old name, so no need to announce again.
|
||||||
// TODO bcs of persistance being async, there is a small window of time, when someone else could claim the name before it is restored
|
// TODO bcs of persistance being async, there is a small window of time, when someone else could claim the name before it is restored
|
||||||
// which means that names are not guaranteed unique. That should be fine, as only ID's by design are intended unique, but the dev might rely on name uniqueness, bcs of the identify protocol constraints
|
// which means that names are not guaranteed unique. That should be fine, as only ID's by design are intended unique, but the dev might rely on name uniqueness, bcs of the identify protocol constraints
|
||||||
if(this.config?.name && this.config.persistent !== true)
|
if (this.config?.name && successful_recon !== true) //attempt to identify, if has a name and if a recon was tried, but unsuccessful (which includes not a having a token stored)
|
||||||
this.IdentifySelf(this.config.name);
|
this.IdentifySelf(this.config.name);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -729,12 +730,14 @@ export class SocioClient extends LogHandler {
|
||||||
this.Send(ServerMessageKind.RECON, { id, type: 'USE', token } as S_RECON_USE_data);
|
this.Send(ServerMessageKind.RECON, { id, type: 'USE', token } as S_RECON_USE_data);
|
||||||
const res = await (prom as unknown as Promise<C_RECON_Data>);
|
const res = await (prom as unknown as Promise<C_RECON_Data>);
|
||||||
this.#Reconnect(res); //sets the trusted values from the server, like auth bool
|
this.#Reconnect(res); //sets the trusted values from the server, like auth bool
|
||||||
}
|
return res.result.success === 1;
|
||||||
|
}else return false;
|
||||||
}
|
}
|
||||||
//sets the trusted values from the server, like auth bool
|
//sets the trusted values from the server, like auth bool
|
||||||
#Reconnect(data:C_RECON_Data){
|
#Reconnect(data:C_RECON_Data){
|
||||||
if (data.result.success === 1) {
|
if (data.result.success === 1) {
|
||||||
this.#authenticated = data.auth;
|
this.#authenticated = data.auth;
|
||||||
|
this.config.name = data.name;
|
||||||
this.done(`${this.config.name} reconnected successfully. ${data.old_client_id} -> ${this.#client_id} (old client ID -> new/current client ID)`, data);
|
this.done(`${this.config.name} reconnected successfully. ${data.old_client_id} -> ${this.#client_id} (old client ID -> new/current client ID)`, data);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
|
||||||
|
|
@ -960,6 +960,9 @@ export class SocioServer extends LogHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stop deletion of old session for a moment
|
||||||
|
// copy old sesh info to new sesh, cuz thats the new TCP connection
|
||||||
|
// destroy old sesh for good
|
||||||
ReconnectClientSession(new_session: SocioSession, old_session: SocioSession, client_notify_msg_id?:id){
|
ReconnectClientSession(new_session: SocioSession, old_session: SocioSession, client_notify_msg_id?:id){
|
||||||
const new_id = new_session.id, old_id = old_session.id;
|
const new_id = new_session.id, old_id = old_session.id;
|
||||||
old_session.Restore();//stop the old session deletion, since a reconnect was actually attempted
|
old_session.Restore();//stop the old session deletion, since a reconnect was actually attempted
|
||||||
|
|
@ -976,7 +979,7 @@ export class SocioServer extends LogHandler {
|
||||||
}, this.session_defaults.session_delete_delay_ms as number);
|
}, this.session_defaults.session_delete_delay_ms as number);
|
||||||
|
|
||||||
//notify the client
|
//notify the client
|
||||||
const data = { result: { success: 1 }, old_client_id: old_id, auth: new_session.authenticated };
|
const data = { result: { success: 1 }, old_client_id: old_id, auth: new_session.authenticated, name:new_session.name };
|
||||||
if (client_notify_msg_id) data['id'] = client_notify_msg_id;
|
if (client_notify_msg_id) data['id'] = client_notify_msg_id;
|
||||||
new_session.Send(ClientMessageKind.RECON, data as C_RECON_Data);
|
new_session.Send(ClientMessageKind.RECON, data as C_RECON_Data);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -132,9 +132,10 @@ export class SocioSession extends LogHandler {
|
||||||
CopySessionFrom(old_client:SocioSession){
|
CopySessionFrom(old_client:SocioSession){
|
||||||
this.#authenticated = old_client.#authenticated;
|
this.#authenticated = old_client.#authenticated;
|
||||||
this.#perms = old_client.#perms;
|
this.#perms = old_client.#perms;
|
||||||
this.#ws['socio_client_ipAddr'] = old_client.ipAddr;
|
// this.#ws['socio_client_ipAddr'] = old_client.ipAddr; //prob should keep the new IP, in case reconnecting from another computer or smth
|
||||||
this.verbose = old_client.verbose;
|
this.verbose = old_client.verbose;
|
||||||
this.last_seen = old_client.last_seen;
|
this.last_seen = old_client.last_seen;
|
||||||
|
// this.last_seen_now();
|
||||||
this.name = old_client.name;
|
this.name = old_client.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
4
core/package-lock.json
generated
4
core/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "socio",
|
"name": "socio",
|
||||||
"version": "1.13.4",
|
"version": "1.13.5",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "socio",
|
"name": "socio",
|
||||||
"version": "1.13.4",
|
"version": "1.13.5",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "socio",
|
"name": "socio",
|
||||||
"version": "1.13.4",
|
"version": "1.13.5",
|
||||||
"description": "A WebSocket Real-Time Communication (RTC) API framework.",
|
"description": "A WebSocket Real-Time Communication (RTC) API framework.",
|
||||||
"main": "./dist/core.js",
|
"main": "./dist/core.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|
|
||||||
2
core/types.d.ts
vendored
2
core/types.d.ts
vendored
|
|
@ -101,7 +101,7 @@ type C_UPD_data = data_base & data_result_block;
|
||||||
type C_AUTH_data = data_base & data_result_block;
|
type C_AUTH_data = data_base & data_result_block;
|
||||||
type C_GET_PERM_data = data_base & data_result_block & { verb: string, table: string };
|
type C_GET_PERM_data = data_base & data_result_block & { verb: string, table: string };
|
||||||
type C_PROP_UPD_data = data_base & { prop: string } & ({ prop_val: PropValue } | { prop_val_diff: diff_lib.rdiffResult[] });
|
type C_PROP_UPD_data = data_base & { prop: string } & ({ prop_val: PropValue } | { prop_val_diff: diff_lib.rdiffResult[] });
|
||||||
type C_RECON_Data = data_base & data_result_block & { old_client_id: ClientID, auth: boolean };
|
type C_RECON_Data = data_base & data_result_block & { old_client_id: ClientID, auth: boolean, name?:string };
|
||||||
type C_RECV_FILES_Data = data_base & data_result_block & { files: SocioFiles };
|
type C_RECV_FILES_Data = data_base & data_result_block & { files: SocioFiles };
|
||||||
// type C_PROP_REG_data = data_base & data_result_block & { prop?: string, initial_value: any, opts: Omit<PropOpts, "observationaly_temporary"> };
|
// type C_PROP_REG_data = data_base & data_result_block & { prop?: string, initial_value: any, opts: Omit<PropOpts, "observationaly_temporary"> };
|
||||||
type ClientMessageDataObj = data_base | CON_data | RES_data | AUTH_data | PROP_UPD_data | RECON_Data | RECV_FILES_Data;
|
type ClientMessageDataObj = data_base | CON_data | RES_data | AUTH_data | PROP_UPD_data | RECON_Data | RECV_FILES_Data;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue