mirror of
https://github.com/koush/scrypted.git
synced 2026-03-20 16:40:24 +00:00
rpc: add support for setting properties on RpcProxy
This commit is contained in:
@@ -109,8 +109,14 @@ class RpcProxy implements PrimitiveProxyHandler<any> {
|
||||
}
|
||||
|
||||
set(target: any, p: string | symbol, value: any, receiver: any): boolean {
|
||||
if (p === RpcPeer.finalizerIdSymbol)
|
||||
if (p === RpcPeer.finalizerIdSymbol) {
|
||||
this.entry.finalizerId = value;
|
||||
}
|
||||
else {
|
||||
this.proxyProps ||= {};
|
||||
this.proxyProps[p] = value;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
23
server/test/rpc-proxy-set.ts
Normal file
23
server/test/rpc-proxy-set.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { RpcPeer } from "../src/rpc";
|
||||
|
||||
const p1 = new RpcPeer('p1', 'p2', message => {
|
||||
p2.handleMessage(message);
|
||||
});
|
||||
|
||||
const p2 = new RpcPeer('p2', 'p1', message => {
|
||||
p1.handleMessage(message);
|
||||
});
|
||||
|
||||
class Foo {
|
||||
}
|
||||
|
||||
p1.params['thing'] = new Foo();
|
||||
|
||||
async function test() {
|
||||
const foo = await p2.getParam('thing');
|
||||
foo.bar = 3;
|
||||
if (foo.bar !== 3)
|
||||
throw new Error('proxy custom property set failed');
|
||||
}
|
||||
|
||||
test();
|
||||
Reference in New Issue
Block a user