feat: pass provider instance to RPCSession constructor in RPCClient and RPCServer
This commit is contained in:
@@ -85,6 +85,7 @@ export class RPCClient {
|
||||
resolve(new RPCSession(
|
||||
new RPCConnection(connection!),
|
||||
this.rpcHandler,
|
||||
this,
|
||||
));
|
||||
} else {
|
||||
reject(new Error('Server rejected handshake request'));
|
||||
|
||||
@@ -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<RPCConnectionEvents> {
|
||||
closed: boolean = false;
|
||||
|
||||
private callResponseEmitter = new CallResponseEmitter();
|
||||
private rpcSession!: RPCSession;
|
||||
|
||||
constructor(public socket: SocketConnection) {
|
||||
super();
|
||||
@@ -75,6 +77,10 @@ export class RPCConnection extends EventEmitter<RPCConnectionEvents> {
|
||||
})
|
||||
}
|
||||
|
||||
public setRPCSession(session: RPCSession) {
|
||||
this.rpcSession = session;
|
||||
}
|
||||
|
||||
/** @throws */
|
||||
public async callRequest(options: {
|
||||
fnPath: string;
|
||||
|
||||
@@ -78,6 +78,7 @@ export class RPCServer extends EventEmitter<RPCServerEvents> {
|
||||
this.emit('connect', new RPCSession(
|
||||
new RPCConnection(socketConnection),
|
||||
this.rpcHandler,
|
||||
this,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user