Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 67x 67x 67x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 67x 67x 67x 67x 67x 67x 67x 54x 54x 54x 54x 67x 67x 621x 621x 510x 621x 202x 621x 177x 621x 120x 621x 120x 621x 120x 621x 55x 621x 51x 51x 1x 1x 1x 51x 51x 51x 55x 55x 67x 67x 67x 67x 1x | import { inlineRemotable } from "./inline-remotable";
import { OBJECT_ID, REFERENCE_ID } from "./internal";
import { Proxied } from "./proxied";
import { Remotable } from "./remotable";
import { RPCSession } from "./session";
/**
* Provides a proxy for a remote object for which a reference is held by the local Conduit session.
* This allows seamless async RPC calls and event (observable) subscriptions.
*/
@Remotable()
export class RPCProxy {
private constructor(id: string, referenceId: string) {
this[OBJECT_ID] = id;
this[REFERENCE_ID] = referenceId;
}
[OBJECT_ID]?: string;
[REFERENCE_ID]?: string;
/**
* Construct a new proxy for the given object reference, which is held by the given Conduit session.
* Any method calls to this proxy will be sent as Conduit method calls over the given session.
*
* @param session The session which owns the remote reference
* @param objectId The unique ID of the remote object
* @param referenceId The ID of the object reference that this remote object will hold.
* @returns
*/
static create<T = any>(session: RPCSession, objectId: string, referenceId: string): Proxied<T> {
const methodMap = new Map<string, Function>();
let proxy: Proxied<T>;
let metadata: Record<string, any>;
proxy = <Proxied<T>>new Proxy(new RPCProxy(objectId, referenceId), {
set(t, p, v) {
if (p === 'metadata') {
metadata = v;
return true;
}
t[p] = v;
return true;
},
get(t, p, __) {
if (p === 'constructor')
return RPCProxy;
if (p === OBJECT_ID)
return objectId;
if (p === REFERENCE_ID)
return referenceId;
if (p === 'toJSON')
return () => session.remoteRef(proxy);
if (p === 'toString')
return () => `[RemoteObject ${objectId}]`;
if (p === 'metadata')
return metadata;
if (p === 'then')
return undefined;
if (!methodMap.has(String(p))) {
let method = (...args) => session.call(proxy, String(p), args);
method['subscribe'] = (observer: (t: any) => void) => {
return session.remote.subscribeToEvent(proxy, String(p), inlineRemotable({
next: t => observer(t)
}));
};
methodMap.set(String(p), method);
}
return methodMap.get(String(p));
}
});
return proxy;
}
}
|