@scrypted/server 0.115.0 → 0.115.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/deno/deno-plugin-remote.ts +4 -0
  2. package/dist/cluster/cluster-hash.js +1 -1
  3. package/dist/cluster/cluster-hash.js.map +1 -1
  4. package/dist/cluster/connect-rpc-object.d.ts +2 -1
  5. package/dist/plugin/plugin-api.d.ts +1 -0
  6. package/dist/plugin/plugin-remote-stats.js +19 -15
  7. package/dist/plugin/plugin-remote-stats.js.map +1 -1
  8. package/dist/plugin/plugin-remote-worker.js +90 -54
  9. package/dist/plugin/plugin-remote-worker.js.map +1 -1
  10. package/dist/plugin/runtime/deno-worker.d.ts +12 -0
  11. package/dist/plugin/runtime/deno-worker.js +84 -0
  12. package/dist/plugin/runtime/deno-worker.js.map +1 -0
  13. package/dist/plugin/runtime/node-fork-worker.d.ts +1 -1
  14. package/dist/plugin/runtime/node-fork-worker.js +2 -2
  15. package/dist/plugin/runtime/node-fork-worker.js.map +1 -1
  16. package/dist/plugin/runtime/node-thread-worker.d.ts +3 -3
  17. package/dist/plugin/runtime/node-thread-worker.js +22 -7
  18. package/dist/plugin/runtime/node-thread-worker.js.map +1 -1
  19. package/dist/rpc-peer-eval.d.ts +4 -1
  20. package/dist/rpc-peer-eval.js +4 -10
  21. package/dist/rpc-peer-eval.js.map +1 -1
  22. package/dist/rpc.d.ts +4 -1
  23. package/dist/rpc.js +8 -4
  24. package/dist/rpc.js.map +1 -1
  25. package/dist/runtime.js +2 -0
  26. package/dist/runtime.js.map +1 -1
  27. package/dist/scrypted-main-exports.js +2 -2
  28. package/dist/scrypted-main-exports.js.map +1 -1
  29. package/dist/scrypted-main.js +4 -1
  30. package/dist/scrypted-main.js.map +1 -1
  31. package/dist/scrypted-plugin-main.js +14 -4
  32. package/dist/scrypted-plugin-main.js.map +1 -1
  33. package/package.json +4 -3
  34. package/python/plugin_remote.py +423 -221
  35. package/python/rpc.py +10 -10
  36. package/src/cluster/cluster-hash.ts +1 -1
  37. package/src/cluster/connect-rpc-object.ts +2 -1
  38. package/src/plugin/plugin-api.ts +1 -0
  39. package/src/plugin/plugin-remote-stats.ts +20 -15
  40. package/src/plugin/plugin-remote-worker.ts +103 -56
  41. package/src/plugin/runtime/deno-worker.ts +91 -0
  42. package/src/plugin/runtime/node-fork-worker.ts +3 -5
  43. package/src/plugin/runtime/node-thread-worker.ts +22 -6
  44. package/src/rpc-peer-eval.ts +9 -14
  45. package/src/rpc.ts +17 -7
  46. package/src/runtime.ts +2 -0
  47. package/src/scrypted-main-exports.ts +2 -2
  48. package/src/scrypted-main.ts +4 -1
  49. package/src/scrypted-plugin-main.ts +14 -4
package/src/rpc.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  export function startPeriodicGarbageCollection() {
2
- if (!global.gc) {
2
+ if (!globalThis.gc) {
3
3
  console.warn('rpc peer garbage collection not available: global.gc is not exposed.');
4
4
  }
5
- let g: typeof global;
5
+ let g: typeof globalThis;
6
6
  try {
7
- g = global;
7
+ g = globalThis;
8
8
  }
9
9
  catch (e) {
10
10
  }
@@ -304,7 +304,10 @@ export class RpcPeer {
304
304
  finalizers = new FinalizationRegistry(entry => this.finalize(entry as LocalProxiedEntry));
305
305
  nameDeserializerMap = new Map<string, RpcSerializer>();
306
306
  onProxyTypeSerialization = new Map<string, (value: any) => void>();
307
- onProxySerialization: (value: any, proxyId: string) => any;
307
+ onProxySerialization: (value: any) => {
308
+ proxyId: string;
309
+ properties: any;
310
+ };
308
311
  constructorSerializerMap = new Map<any, string>();
309
312
  transportSafeArgumentTypes = RpcPeer.getDefaultTransportSafeArgumentTypes();
310
313
  killed: Promise<string>;
@@ -630,7 +633,16 @@ export class RpcPeer {
630
633
 
631
634
  this.onProxyTypeSerialization.get(__remote_constructor_name)?.(value);
632
635
 
633
- const __remote_proxy_id = RpcPeer.generateId();
636
+ const {
637
+ proxyId: __remote_proxy_id,
638
+ properties: __remote_proxy_props,
639
+ } = this.onProxySerialization
640
+ ? this.onProxySerialization(value)
641
+ : {
642
+ proxyId: RpcPeer.generateId(),
643
+ properties: RpcPeer.prepareProxyProperties(value),
644
+ };
645
+
634
646
  proxiedEntry = {
635
647
  id: __remote_proxy_id,
636
648
  finalizerId: __remote_proxy_id,
@@ -638,8 +650,6 @@ export class RpcPeer {
638
650
  this.localProxied.set(value, proxiedEntry);
639
651
  this.localProxyMap.set(__remote_proxy_id, value);
640
652
 
641
- const __remote_proxy_props = this.onProxySerialization ? this.onProxySerialization(value, __remote_proxy_id) : RpcPeer.prepareProxyProperties(value);
642
-
643
653
  const ret: RpcRemoteProxyValue = {
644
654
  __remote_proxy_id,
645
655
  __remote_proxy_finalizer_id: __remote_proxy_id,
package/src/runtime.ts CHANGED
@@ -46,6 +46,7 @@ import { getNpmPackageInfo, PluginComponent } from './services/plugin';
46
46
  import { ServiceControl } from './services/service-control';
47
47
  import { UsersService } from './services/users';
48
48
  import { getState, ScryptedStateManager, setState } from './state';
49
+ import { DenoWorker } from './plugin/runtime/deno-worker';
49
50
 
50
51
  interface DeviceProxyPair {
51
52
  handler: PluginDeviceProxyHandler;
@@ -102,6 +103,7 @@ export class ScryptedRuntime extends PluginHttp<HttpPluginData> {
102
103
  this.pluginHosts.set('custom', (_, pluginId, options, runtime) => new CustomRuntimeWorker(pluginId, options, runtime));
103
104
  this.pluginHosts.set('python', (_, pluginId, options) => new PythonRuntimeWorker(pluginId, options));
104
105
  this.pluginHosts.set('node', (mainFilename, pluginId, options) => new NodeForkWorker(mainFilename, pluginId, options));
106
+ this.pluginHosts.set('deno', (mainFilename, pluginId, options) => new DenoWorker(mainFilename, pluginId, options));
105
107
 
106
108
  app.disable('x-powered-by');
107
109
 
@@ -25,9 +25,9 @@ function start(mainFilename: string, options?: {
25
25
  require(process.env.SCRYPTED_COMPATIBILITY_FILE);
26
26
  }
27
27
 
28
- if (!global.gc) {
28
+ if (!globalThis.gc && !process.versions.deno) {
29
29
  v8.setFlagsFromString('--expose_gc')
30
- global.gc = vm.runInNewContext("gc");
30
+ globalThis.gc = vm.runInNewContext("gc");
31
31
  }
32
32
 
33
33
  if (!semver.gte(process.version, '16.0.0')) {
@@ -1,3 +1,6 @@
1
1
  import start from './scrypted-main-exports';
2
2
 
3
- start(__filename);
3
+ if (process.versions.deno)
4
+ start(process.env.SCRYPTED_MAIN_FILENAME);
5
+ else
6
+ start(__filename);
@@ -8,13 +8,14 @@ import { RpcMessage } from "./rpc";
8
8
 
9
9
  function start(mainFilename: string) {
10
10
  const pluginId = process.argv[3];
11
- console.log('starting plugin', pluginId);
12
11
  module.paths.push(getPluginNodePath(pluginId));
13
12
 
14
13
  if (process.argv[2] === 'child-thread') {
15
- const peer = startPluginRemote(mainFilename, process.argv[3], (message, reject) => {
14
+ console.log('starting thread', pluginId);
15
+ const { port } = worker_threads.workerData as { port: worker_threads.MessagePort };
16
+ const peer = startPluginRemote(mainFilename, pluginId, (message, reject) => {
16
17
  try {
17
- worker_threads.parentPort.postMessage(v8.serialize(message));
18
+ port.postMessage(v8.serialize(message));
18
19
  }
19
20
  catch (e) {
20
21
  reject?.(e);
@@ -22,9 +23,18 @@ function start(mainFilename: string) {
22
23
  });
23
24
  peer.transportSafeArgumentTypes.add(Buffer.name);
24
25
  peer.transportSafeArgumentTypes.add(Uint8Array.name);
25
- worker_threads.parentPort.on('message', message => peer.handleMessage(v8.deserialize(message)));
26
+ port.on('message', message => peer.handleMessage(v8.deserialize(message)));
27
+ port.on('messageerror', e => {
28
+ console.error('message error', e);
29
+ process.exit(1);
30
+ });
31
+ port.on('close', () => {
32
+ console.error('port closed');
33
+ process.exit(1);
34
+ });
26
35
  }
27
36
  else {
37
+ console.log('starting plugin', pluginId);
28
38
  const peer = startPluginRemote(mainFilename, process.argv[3], (message, reject, serializationContext) => process.send(message, serializationContext?.sendHandle, {
29
39
  swallowErrors: !reject,
30
40
  }, e => {