diff --git a/src/core/RPCClient.ts b/src/core/RPCClient.ts index 743323f..0e2f6d2 100644 --- a/src/core/RPCClient.ts +++ b/src/core/RPCClient.ts @@ -85,6 +85,7 @@ export class RPCClient { resolve(new RPCSession( new RPCConnection(connection!), this.rpcHandler, + this, )); } else { reject(new Error('Server rejected handshake request')); diff --git a/src/core/RPCConnection.ts b/src/core/RPCConnection.ts index 199e10b..c7c0b83 100644 --- a/src/core/RPCConnection.ts +++ b/src/core/RPCConnection.ts @@ -4,6 +4,7 @@ import { RPCPacket } from "./RPCPacket"; import { makeCallPacket, makeCallResponsePacket, parseCallPacket, parseCallResponsePacket } from "./RPCCommon"; import { RPCProvider } from "./RPCProvider"; import { RPCError, RPCErrorCode } from "./RPCError"; +import { RPCSession } from "./RPCSession"; interface RPCConnectionEvents { call: RPCPacket; @@ -29,6 +30,7 @@ export class RPCConnection extends EventEmitter { closed: boolean = false; private callResponseEmitter = new CallResponseEmitter(); + private rpcSession!: RPCSession; constructor(public socket: SocketConnection) { super(); @@ -75,6 +77,10 @@ export class RPCConnection extends EventEmitter { }) } + public setRPCSession(session: RPCSession) { + this.rpcSession = session; + } + /** @throws */ public async callRequest(options: { fnPath: string; diff --git a/src/core/RPCServer.ts b/src/core/RPCServer.ts index 8767d47..afaf970 100644 --- a/src/core/RPCServer.ts +++ b/src/core/RPCServer.ts @@ -78,6 +78,7 @@ export class RPCServer extends EventEmitter { this.emit('connect', new RPCSession( new RPCConnection(socketConnection), this.rpcHandler, + this, )); } diff --git a/src/core/RPCSession.ts b/src/core/RPCSession.ts index 399b58d..61a6034 100644 --- a/src/core/RPCSession.ts +++ b/src/core/RPCSession.ts @@ -2,6 +2,8 @@ import { ToDeepPromise } from "@/utils/utils"; import { RPCConnection } from "./RPCConnection"; import { RPCHandler } from "./RPCHandler"; import { RPCProvider } from "./RPCProvider"; +import { RPCClient } from "./RPCClient"; +import { RPCServer } from "./RPCServer"; export class RPCSession { @@ -9,7 +11,9 @@ export class RPCSession { constructor( public readonly connection: RPCConnection, public readonly rpcHandler: RPCHandler, + public readonly provider: RPCClient | RPCServer, ) { + connection.setRPCSession(this); connection.onCallRequest(rpcHandler.getProvider.bind(rpcHandler)); }