mirror of
https://github.com/Rolands-Laucis/Socio.git
synced 2026-05-15 06:05:53 -06:00
fix recon and add recon hook
This commit is contained in:
parent
cdb1d2f41e
commit
3b8dc057ae
2 changed files with 11 additions and 2 deletions
|
|
@ -564,6 +564,8 @@ export class SocioServer extends LogHandler {
|
|||
|
||||
//recon procedure
|
||||
const old_client = this.#sessions.get(old_c_id) as SocioSession;
|
||||
this.ReconnectClientSession(client, old_client, data.id as id);
|
||||
this.HandleInfo(`RECON | old id: ${old_c_id} -> new id: ${client.id}`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -991,9 +993,15 @@ 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) {
|
||||
const new_id = new_session.id, old_id = old_session.id;
|
||||
async ReconnectClientSession(new_session: SocioSession, old_session: SocioSession, client_notify_msg_id?: id) {
|
||||
old_session.Restore();//stop the old session deletion, since a reconnect was actually attempted
|
||||
|
||||
// dev can handle the hook themselves
|
||||
if(this.lifecycle_hooks.recon){
|
||||
if(await this.lifecycle_hooks.recon(old_session, new_session)) return;
|
||||
}
|
||||
|
||||
const new_id = new_session.id, old_id = old_session.id;
|
||||
new_session.CopySessionFrom(old_session);
|
||||
|
||||
//clear the subscriptions on the sockets, since the new instance will define new ones on the new page. Also to avoid ID conflicts
|
||||
|
|
|
|||
1
core/types.d.ts
vendored
1
core/types.d.ts
vendored
|
|
@ -49,6 +49,7 @@ type ServerHookDefinitions = {
|
|||
identify?: (caller_client: SocioSession, name: string) => Promise<void>,
|
||||
discovery?: (caller_client: SocioSession, data: MessageDataObj) => Promise<{ [client_id: string]: { name?: string, ip: string, [key: string]: any } } | any>,
|
||||
rpc?: (target_client: ClientID | string | null, f_name: string, args: any[]) => Promise<any> | any,
|
||||
recon?: (old_session: SocioSession, new_session: SocioSession) => boolean | Promise<boolean>,
|
||||
};
|
||||
// Use a mapped type to define individual importable types. Import this and use like ServerLifecycleHooks['con']
|
||||
type ServerLifecycleHooks = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue