@scrypted/server 0.7.93 → 0.7.94

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.

Potentially problematic release.


This version of @scrypted/server might be problematic. Click here for more details.

Files changed (184) hide show
  1. package/dist/asynciterable-utils.d.ts +2 -0
  2. package/dist/asynciterable-utils.js +24 -0
  3. package/dist/asynciterable-utils.js.map +1 -0
  4. package/dist/cert.d.ts +6 -0
  5. package/dist/cert.js +75 -0
  6. package/dist/cert.js.map +1 -0
  7. package/dist/collection.d.ts +1 -0
  8. package/dist/collection.js +16 -0
  9. package/dist/collection.js.map +1 -0
  10. package/dist/db-types.d.ts +38 -0
  11. package/dist/db-types.js +45 -0
  12. package/dist/db-types.js.map +1 -0
  13. package/dist/event-registry.d.ts +19 -0
  14. package/dist/event-registry.js +92 -0
  15. package/dist/event-registry.js.map +1 -0
  16. package/dist/http-interfaces.d.ts +3 -0
  17. package/dist/http-interfaces.js +73 -0
  18. package/dist/http-interfaces.js.map +1 -0
  19. package/dist/infer-defaults.d.ts +11 -0
  20. package/dist/infer-defaults.js +119 -0
  21. package/dist/infer-defaults.js.map +1 -0
  22. package/dist/io.d.ts +22 -0
  23. package/dist/io.js +3 -0
  24. package/dist/io.js.map +1 -0
  25. package/dist/level.d.ts +110 -0
  26. package/dist/level.js +135 -0
  27. package/dist/level.js.map +1 -0
  28. package/dist/listen-zero.d.ts +13 -0
  29. package/dist/listen-zero.js +48 -0
  30. package/dist/listen-zero.js.map +1 -0
  31. package/dist/logger.d.ts +29 -0
  32. package/dist/logger.js +78 -0
  33. package/dist/logger.js.map +1 -0
  34. package/dist/media-helpers.d.ts +5 -0
  35. package/dist/media-helpers.js +89 -0
  36. package/dist/media-helpers.js.map +1 -0
  37. package/dist/mixin/mixin-cycle.d.ts +3 -0
  38. package/dist/mixin/mixin-cycle.js +32 -0
  39. package/dist/mixin/mixin-cycle.js.map +1 -0
  40. package/dist/plugin/acl.d.ts +16 -0
  41. package/dist/plugin/acl.js +83 -0
  42. package/dist/plugin/acl.js.map +1 -0
  43. package/dist/plugin/descriptor.d.ts +22 -0
  44. package/dist/plugin/descriptor.js +35 -0
  45. package/dist/plugin/descriptor.js.map +1 -0
  46. package/dist/plugin/media.d.ts +71 -0
  47. package/dist/plugin/media.js +420 -0
  48. package/dist/plugin/media.js.map +1 -0
  49. package/dist/plugin/mediaobject.d.ts +10 -0
  50. package/dist/plugin/mediaobject.js +26 -0
  51. package/dist/plugin/mediaobject.js.map +1 -0
  52. package/dist/plugin/plugin-api.d.ts +106 -0
  53. package/dist/plugin/plugin-api.js +120 -0
  54. package/dist/plugin/plugin-api.js.map +1 -0
  55. package/dist/plugin/plugin-console.d.ts +28 -0
  56. package/dist/plugin/plugin-console.js +291 -0
  57. package/dist/plugin/plugin-console.js.map +1 -0
  58. package/dist/plugin/plugin-debug.d.ts +4 -0
  59. package/dist/plugin/plugin-debug.js +3 -0
  60. package/dist/plugin/plugin-debug.js.map +1 -0
  61. package/dist/plugin/plugin-device.d.ts +54 -0
  62. package/dist/plugin/plugin-device.js +413 -0
  63. package/dist/plugin/plugin-device.js.map +1 -0
  64. package/dist/plugin/plugin-error.d.ts +2 -0
  65. package/dist/plugin/plugin-error.js +7 -0
  66. package/dist/plugin/plugin-error.js.map +1 -0
  67. package/dist/plugin/plugin-host-api.d.ts +43 -0
  68. package/dist/plugin/plugin-host-api.js +177 -0
  69. package/dist/plugin/plugin-host-api.js.map +1 -0
  70. package/dist/plugin/plugin-host.d.ts +45 -0
  71. package/dist/plugin/plugin-host.js +398 -0
  72. package/dist/plugin/plugin-host.js.map +1 -0
  73. package/dist/plugin/plugin-http.d.ts +18 -0
  74. package/dist/plugin/plugin-http.js +120 -0
  75. package/dist/plugin/plugin-http.js.map +1 -0
  76. package/dist/plugin/plugin-lazy-remote.d.ts +31 -0
  77. package/dist/plugin/plugin-lazy-remote.js +75 -0
  78. package/dist/plugin/plugin-lazy-remote.js.map +1 -0
  79. package/dist/plugin/plugin-npm-dependencies.d.ts +8 -0
  80. package/dist/plugin/plugin-npm-dependencies.js +103 -0
  81. package/dist/plugin/plugin-npm-dependencies.js.map +1 -0
  82. package/dist/plugin/plugin-remote-stats.d.ts +8 -0
  83. package/dist/plugin/plugin-remote-stats.js +30 -0
  84. package/dist/plugin/plugin-remote-stats.js.map +1 -0
  85. package/dist/plugin/plugin-remote-websocket.d.ts +29 -0
  86. package/dist/plugin/plugin-remote-websocket.js +152 -0
  87. package/dist/plugin/plugin-remote-websocket.js.map +1 -0
  88. package/dist/plugin/plugin-remote-worker.d.ts +5 -0
  89. package/dist/plugin/plugin-remote-worker.js +348 -0
  90. package/dist/plugin/plugin-remote-worker.js.map +1 -0
  91. package/dist/plugin/plugin-remote.d.ts +75 -0
  92. package/dist/plugin/plugin-remote.js +598 -0
  93. package/dist/plugin/plugin-remote.js.map +1 -0
  94. package/dist/plugin/plugin-repl.d.ts +2 -0
  95. package/dist/plugin/plugin-repl.js +74 -0
  96. package/dist/plugin/plugin-repl.js.map +1 -0
  97. package/dist/plugin/plugin-state-check.d.ts +1 -0
  98. package/dist/plugin/plugin-state-check.js +27 -0
  99. package/dist/plugin/plugin-state-check.js.map +1 -0
  100. package/dist/plugin/plugin-volume.d.ts +3 -0
  101. package/dist/plugin/plugin-volume.js +31 -0
  102. package/dist/plugin/plugin-volume.js.map +1 -0
  103. package/dist/plugin/runtime/child-process-worker.d.ts +20 -0
  104. package/dist/plugin/runtime/child-process-worker.js +42 -0
  105. package/dist/plugin/runtime/child-process-worker.js.map +1 -0
  106. package/dist/plugin/runtime/node-fork-worker.d.ts +9 -0
  107. package/dist/plugin/runtime/node-fork-worker.js +67 -0
  108. package/dist/plugin/runtime/node-fork-worker.js.map +1 -0
  109. package/dist/plugin/runtime/node-thread-worker.d.ts +20 -0
  110. package/dist/plugin/runtime/node-thread-worker.js +73 -0
  111. package/dist/plugin/runtime/node-thread-worker.js.map +1 -0
  112. package/dist/plugin/runtime/python-worker.d.ts +10 -0
  113. package/dist/plugin/runtime/python-worker.js +91 -0
  114. package/dist/plugin/runtime/python-worker.js.map +1 -0
  115. package/dist/plugin/runtime/runtime-worker.d.ts +26 -0
  116. package/dist/plugin/runtime/runtime-worker.js +3 -0
  117. package/dist/plugin/runtime/runtime-worker.js.map +1 -0
  118. package/dist/plugin/socket-serializer.d.ts +5 -0
  119. package/dist/plugin/socket-serializer.js +17 -0
  120. package/dist/plugin/socket-serializer.js.map +1 -0
  121. package/dist/plugin/system.d.ts +39 -0
  122. package/dist/plugin/system.js +216 -0
  123. package/dist/plugin/system.js.map +1 -0
  124. package/dist/rpc-buffer-serializer.d.ts +11 -0
  125. package/dist/rpc-buffer-serializer.js +30 -0
  126. package/dist/rpc-buffer-serializer.js.map +1 -0
  127. package/dist/rpc-serializer.d.ts +24 -0
  128. package/dist/rpc-serializer.js +144 -0
  129. package/dist/rpc-serializer.js.map +1 -0
  130. package/dist/rpc.d.ts +147 -0
  131. package/dist/rpc.js +689 -0
  132. package/dist/rpc.js.map +1 -0
  133. package/dist/runtime.d.ts +103 -0
  134. package/dist/runtime.js +815 -0
  135. package/dist/runtime.js.map +1 -0
  136. package/dist/scrypted-main-exports.d.ts +6 -0
  137. package/dist/scrypted-main-exports.js +57 -0
  138. package/dist/scrypted-main-exports.js.map +1 -0
  139. package/dist/scrypted-main.d.ts +1 -0
  140. package/dist/scrypted-main.js +8 -0
  141. package/dist/scrypted-main.js.map +1 -0
  142. package/dist/scrypted-plugin-main.d.ts +2 -0
  143. package/dist/scrypted-plugin-main.js +43 -0
  144. package/dist/scrypted-plugin-main.js.map +1 -0
  145. package/dist/scrypted-server-main.d.ts +6 -0
  146. package/dist/scrypted-server-main.js +559 -0
  147. package/dist/scrypted-server-main.js.map +1 -0
  148. package/dist/server-settings.d.ts +5 -0
  149. package/dist/server-settings.js +91 -0
  150. package/dist/server-settings.js.map +1 -0
  151. package/dist/services/addresses.d.ts +7 -0
  152. package/dist/services/addresses.js +43 -0
  153. package/dist/services/addresses.js.map +1 -0
  154. package/dist/services/alerts.d.ts +9 -0
  155. package/dist/services/alerts.js +27 -0
  156. package/dist/services/alerts.js.map +1 -0
  157. package/dist/services/cors.d.ts +18 -0
  158. package/dist/services/cors.js +18 -0
  159. package/dist/services/cors.js.map +1 -0
  160. package/dist/services/info.d.ts +5 -0
  161. package/dist/services/info.js +18 -0
  162. package/dist/services/info.js.map +1 -0
  163. package/dist/services/plugin.d.ts +46 -0
  164. package/dist/services/plugin.js +172 -0
  165. package/dist/services/plugin.js.map +1 -0
  166. package/dist/services/service-control.d.ts +8 -0
  167. package/dist/services/service-control.js +39 -0
  168. package/dist/services/service-control.js.map +1 -0
  169. package/dist/services/users.d.ts +19 -0
  170. package/dist/services/users.js +75 -0
  171. package/dist/services/users.js.map +1 -0
  172. package/dist/sleep.d.ts +1 -0
  173. package/dist/sleep.js +8 -0
  174. package/dist/sleep.js.map +1 -0
  175. package/dist/state.d.ts +39 -0
  176. package/dist/state.js +247 -0
  177. package/dist/state.js.map +1 -0
  178. package/dist/threading.d.ts +3 -0
  179. package/dist/threading.js +93 -0
  180. package/dist/threading.js.map +1 -0
  181. package/dist/usertoken.d.ts +11 -0
  182. package/dist/usertoken.js +52 -0
  183. package/dist/usertoken.js.map +1 -0
  184. package/package.json +2 -2
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createREPLServer = void 0;
7
+ const listen_zero_1 = require("../listen-zero");
8
+ const net_1 = require("net");
9
+ const events_1 = require("events");
10
+ const repl_1 = __importDefault(require("repl"));
11
+ async function createREPLServer(scrypted, params, plugin) {
12
+ const { deviceManager, systemManager } = scrypted;
13
+ const server = new net_1.Server(async (socket) => {
14
+ let [filter] = await (0, events_1.once)(socket, 'data');
15
+ filter = filter.toString().trim();
16
+ if (filter === 'undefined')
17
+ filter = undefined;
18
+ const chain = [];
19
+ const nativeIds = deviceManager.nativeIds;
20
+ const reversed = new Map();
21
+ for (const nativeId of nativeIds.keys()) {
22
+ reversed.set(nativeIds.get(nativeId).id, nativeId);
23
+ }
24
+ while (filter) {
25
+ const { id } = nativeIds.get(filter);
26
+ const d = await systemManager.getDeviceById(id);
27
+ chain.push(filter);
28
+ filter = reversed.get(d.providerId);
29
+ }
30
+ chain.reverse();
31
+ let device = plugin;
32
+ for (const c of chain) {
33
+ device = await device.getDevice(c);
34
+ }
35
+ const realDevice = systemManager.getDeviceById(device.id);
36
+ const ctx = Object.assign(params, {
37
+ device,
38
+ realDevice,
39
+ sdk: scrypted,
40
+ });
41
+ delete ctx.console;
42
+ delete ctx.window;
43
+ delete ctx.WebSocket;
44
+ delete ctx.pluginHostAPI;
45
+ delete ctx.log;
46
+ delete ctx.pluginRuntimeAPI;
47
+ const replFilter = new Set(['require', 'localStorage', 'exports', '__filename', 'log']);
48
+ const replVariables = Object.keys(ctx).filter(key => !replFilter.has(key));
49
+ const welcome = `JavaScript REPL variables:\n${replVariables.map(key => ' ' + key).join('\n')}\n\n`;
50
+ socket.write(welcome);
51
+ const r = repl_1.default.start({
52
+ terminal: true,
53
+ input: socket,
54
+ output: socket,
55
+ // writer(this: REPLServer, obj: any) {
56
+ // const ret = util.inspect(obj, {
57
+ // colors: true,
58
+ // });
59
+ // return ret;//.replaceAll('\n', '\r\n');
60
+ // },
61
+ preview: false,
62
+ });
63
+ Object.assign(r.context, ctx);
64
+ const cleanup = () => {
65
+ r.close();
66
+ };
67
+ socket.on('close', cleanup);
68
+ socket.on('error', cleanup);
69
+ socket.on('end', cleanup);
70
+ });
71
+ return (0, listen_zero_1.listenZero)(server);
72
+ }
73
+ exports.createREPLServer = createREPLServer;
74
+ //# sourceMappingURL=plugin-repl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-repl.js","sourceRoot":"","sources":["../../src/plugin/plugin-repl.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA4C;AA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,CAAC;QAE9B,MAAM,OAAO,GAAG,GAAG,EAAE;YACjB,CAAC,CAAC,KAAK,EAAE,CAAC;QACd,CAAC,CAAC;QAEF,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5B,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5B,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;IACH,OAAO,IAAA,wBAAU,EAAC,MAAM,CAAC,CAAC;AAC9B,CAAC;AAxED,4CAwEC"}
@@ -0,0 +1 @@
1
+ export declare function checkProperty(key: string, value: any): void;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkProperty = void 0;
4
+ const types_1 = require("@scrypted/types");
5
+ const rpc_1 = require("../rpc");
6
+ const descriptor_1 = require("./descriptor");
7
+ function checkProperty(key, value) {
8
+ if (key === types_1.ScryptedInterfaceProperty.id)
9
+ throw new Error("id is read only");
10
+ if (key === types_1.ScryptedInterfaceProperty.nativeId)
11
+ throw new Error("nativeId is read only");
12
+ if (key === types_1.ScryptedInterfaceProperty.mixins)
13
+ throw new Error("mixins is read only");
14
+ if (key === types_1.ScryptedInterfaceProperty.interfaces)
15
+ throw new Error("interfaces is a read only post-mixin computed property, use providedInterfaces");
16
+ if (rpc_1.RpcPeer.isRpcProxy(value))
17
+ throw new Error('value must be a primitive type');
18
+ const iface = descriptor_1.propertyInterfaces[key.toString()];
19
+ if (iface === types_1.ScryptedInterface.ScryptedDevice) {
20
+ // only allow info to be set, since that doesn't actually change the descriptor
21
+ // or the provided* properties (room, interfaces, name, type).
22
+ if (key !== types_1.ScryptedInterfaceProperty.info)
23
+ throw new Error(`${key.toString()} can not be set. Use DeviceManager.onDevicesChanges or DeviceManager.onDeviceDiscovered to update the device description.`);
24
+ }
25
+ }
26
+ exports.checkProperty = checkProperty;
27
+ //# sourceMappingURL=plugin-state-check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-state-check.js","sourceRoot":"","sources":["../../src/plugin/plugin-state-check.ts"],"names":[],"mappings":";;;AAAA,2CAA+E;AAC/E,gCAAiC;AACjC,6CAAkD;AAElD,SAAgB,aAAa,CAAC,GAAW,EAAE,KAAU;IACjD,IAAI,GAAG,KAAK,iCAAyB,CAAC,EAAE;QACpC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,IAAI,GAAG,KAAK,iCAAyB,CAAC,QAAQ;QAC1C,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC7C,IAAI,GAAG,KAAK,iCAAyB,CAAC,MAAM;QACxC,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAC3C,IAAI,GAAG,KAAK,iCAAyB,CAAC,UAAU;QAC5C,MAAM,IAAI,KAAK,CAAC,gFAAgF,CAAC,CAAC;IACtG,IAAI,aAAO,CAAC,UAAU,CAAC,KAAK,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;IACrD,MAAM,KAAK,GAAG,+BAAkB,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IACjD,IAAI,KAAK,KAAK,yBAAiB,CAAC,cAAc,EAAE;QAC5C,+EAA+E;QAC/E,8DAA8D;QAC9D,IAAI,GAAG,KAAK,iCAAyB,CAAC,IAAI;YACtC,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,2HAA2H,CAAC,CAAC;KACrK;AACL,CAAC;AAlBD,sCAkBC"}
@@ -0,0 +1,3 @@
1
+ export declare function getScryptedVolume(): string;
2
+ export declare function getPluginVolume(pluginId: string): string;
3
+ export declare function ensurePluginVolume(pluginId: string): string;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ensurePluginVolume = exports.getPluginVolume = exports.getScryptedVolume = void 0;
7
+ const os_1 = __importDefault(require("os"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const mkdirp_1 = __importDefault(require("mkdirp"));
10
+ function getScryptedVolume() {
11
+ const volumeDir = process.env.SCRYPTED_VOLUME || path_1.default.join(os_1.default.homedir(), '.scrypted', 'volume');
12
+ return volumeDir;
13
+ }
14
+ exports.getScryptedVolume = getScryptedVolume;
15
+ function getPluginVolume(pluginId) {
16
+ const volume = getScryptedVolume();
17
+ const pluginVolume = path_1.default.join(volume, 'plugins', pluginId);
18
+ return pluginVolume;
19
+ }
20
+ exports.getPluginVolume = getPluginVolume;
21
+ function ensurePluginVolume(pluginId) {
22
+ const pluginVolume = getPluginVolume(pluginId);
23
+ try {
24
+ mkdirp_1.default.sync(pluginVolume);
25
+ }
26
+ catch (e) {
27
+ }
28
+ return pluginVolume;
29
+ }
30
+ exports.ensurePluginVolume = ensurePluginVolume;
31
+ //# sourceMappingURL=plugin-volume.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-volume.js","sourceRoot":"","sources":["../../src/plugin/plugin-volume.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,oDAA4B;AAE5B,SAAgB,iBAAiB;IAC7B,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,cAAI,CAAC,IAAI,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;IAChG,OAAO,SAAS,CAAC;AACrB,CAAC;AAHD,8CAGC;AAED,SAAgB,eAAe,CAAC,QAAgB;IAC5C,MAAM,MAAM,GAAG,iBAAiB,EAAE,CAAC;IACnC,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC5D,OAAO,YAAY,CAAC;AACxB,CAAC;AAJD,0CAIC;AAED,SAAgB,kBAAkB,CAAC,QAAgB;IAC/C,MAAM,YAAY,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC/C,IAAI;QACA,gBAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;KAC7B;IACD,OAAO,CAAC,EAAE;KACT;IACD,OAAO,YAAY,CAAC;AACxB,CAAC;AARD,gDAQC"}
@@ -0,0 +1,20 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import { EventEmitter } from "ws";
5
+ import { RuntimeWorker, RuntimeWorkerOptions } from "./runtime-worker";
6
+ import child_process from 'child_process';
7
+ import { RpcMessage, RpcPeer } from "../../rpc";
8
+ export declare abstract class ChildProcessWorker extends EventEmitter implements RuntimeWorker {
9
+ pluginId: string;
10
+ worker: child_process.ChildProcess;
11
+ constructor(pluginId: string, options: RuntimeWorkerOptions);
12
+ setupWorker(): void;
13
+ get pid(): number;
14
+ get stdout(): import("stream").Readable;
15
+ get stderr(): import("stream").Readable;
16
+ get killed(): boolean;
17
+ kill(): void;
18
+ abstract send(message: RpcMessage, reject?: (e: Error) => void): void;
19
+ abstract setupRpcPeer(peer: RpcPeer): void;
20
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChildProcessWorker = void 0;
4
+ const ws_1 = require("ws");
5
+ class ChildProcessWorker extends ws_1.EventEmitter {
6
+ pluginId;
7
+ worker;
8
+ constructor(pluginId, options) {
9
+ super();
10
+ this.pluginId = pluginId;
11
+ }
12
+ setupWorker() {
13
+ this.worker.on('close', () => this.emit('close'));
14
+ this.worker.on('disconnect', () => this.emit('disconnect'));
15
+ this.worker.on('exit', (code, signal) => this.emit('exit', code, signal));
16
+ this.worker.on('close', () => this.emit('close'));
17
+ this.worker.on('error', e => this.emit('error', e));
18
+ }
19
+ get pid() {
20
+ return this.worker.pid;
21
+ }
22
+ get stdout() {
23
+ return this.worker.stdout;
24
+ }
25
+ get stderr() {
26
+ return this.worker.stderr;
27
+ }
28
+ get killed() {
29
+ return this.worker.killed;
30
+ }
31
+ kill() {
32
+ if (!this.worker)
33
+ return;
34
+ this.worker.kill('SIGKILL');
35
+ this.worker.removeAllListeners();
36
+ this.worker.stdout.removeAllListeners();
37
+ this.worker.stderr.removeAllListeners();
38
+ this.worker = undefined;
39
+ }
40
+ }
41
+ exports.ChildProcessWorker = ChildProcessWorker;
42
+ //# sourceMappingURL=child-process-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"child-process-worker.js","sourceRoot":"","sources":["../../../src/plugin/runtime/child-process-worker.ts"],"names":[],"mappings":";;;AAAA,2BAAkC;AAKlC,MAAsB,kBAAmB,SAAQ,iBAAY;IAGtC;IAFnB,MAAM,CAA6B;IAEnC,YAAmB,QAAgB,EAAE,OAA6B;QAC9D,KAAK,EAAE,CAAC;QADO,aAAQ,GAAR,QAAQ,CAAQ;IAEnC,CAAC;IAED,WAAW;QACP,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QAClD,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC1E,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QAClD,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,GAAG;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;IAC3B,CAAC;IAED,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED,IAAI;QACA,IAAI,CAAC,IAAI,CAAC,MAAM;YACZ,OAAO;QACX,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC5B,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC;QACjC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC;QACxC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC5B,CAAC;CAIJ;AA3CD,gDA2CC"}
@@ -0,0 +1,9 @@
1
+ import { RuntimeWorkerOptions as RuntimeWorkerOptions } from "./runtime-worker";
2
+ import { RpcMessage, RpcPeer } from "../../rpc";
3
+ import { ChildProcessWorker } from "./child-process-worker";
4
+ export declare class NodeForkWorker extends ChildProcessWorker {
5
+ constructor(mainFilename: string, pluginId: string, options: RuntimeWorkerOptions);
6
+ setupRpcPeer(peer: RpcPeer): void;
7
+ send(message: RpcMessage, reject?: (e: Error) => void, serializationContext?: any): void;
8
+ get pid(): number;
9
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NodeForkWorker = void 0;
7
+ const child_process_1 = __importDefault(require("child_process"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const child_process_worker_1 = require("./child-process-worker");
10
+ const plugin_npm_dependencies_1 = require("../plugin-npm-dependencies");
11
+ const socket_serializer_1 = require("../socket-serializer");
12
+ const net_1 = __importDefault(require("net"));
13
+ class NodeForkWorker extends child_process_worker_1.ChildProcessWorker {
14
+ constructor(mainFilename, pluginId, options) {
15
+ super(pluginId, options);
16
+ const { env, pluginDebug } = options;
17
+ const execArgv = process.execArgv.slice();
18
+ if (pluginDebug) {
19
+ execArgv.push(`--inspect=0.0.0.0:${pluginDebug.inspectPort}`);
20
+ }
21
+ this.worker = child_process_1.default.fork(mainFilename, ['child', this.pluginId], {
22
+ stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
23
+ env: Object.assign({}, process.env, env, {
24
+ NODE_PATH: path_1.default.join((0, plugin_npm_dependencies_1.getPluginNodePath)(this.pluginId), 'node_modules'),
25
+ }),
26
+ serialization: 'advanced',
27
+ execArgv,
28
+ });
29
+ this.setupWorker();
30
+ }
31
+ setupRpcPeer(peer) {
32
+ this.worker.on('message', (message, sendHandle) => {
33
+ if (message.type && sendHandle) {
34
+ peer.handleMessage(message, {
35
+ sendHandle,
36
+ });
37
+ }
38
+ else if (sendHandle) {
39
+ this.emit('rpc', message, sendHandle);
40
+ }
41
+ else {
42
+ peer.handleMessage(message);
43
+ }
44
+ });
45
+ peer.transportSafeArgumentTypes.add(Buffer.name);
46
+ peer.transportSafeArgumentTypes.add(Uint8Array.name);
47
+ peer.addSerializer(net_1.default.Socket, net_1.default.Socket.name, new socket_serializer_1.SidebandSocketSerializer());
48
+ }
49
+ send(message, reject, serializationContext) {
50
+ try {
51
+ if (!this.worker)
52
+ throw new Error('fork worker has been killed');
53
+ this.worker.send(message, serializationContext?.sendHandle, e => {
54
+ if (e && reject)
55
+ reject(e);
56
+ });
57
+ }
58
+ catch (e) {
59
+ reject?.(e);
60
+ }
61
+ }
62
+ get pid() {
63
+ return this.worker?.pid;
64
+ }
65
+ }
66
+ exports.NodeForkWorker = NodeForkWorker;
67
+ //# sourceMappingURL=node-fork-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-fork-worker.js","sourceRoot":"","sources":["../../../src/plugin/runtime/node-fork-worker.ts"],"names":[],"mappings":";;;;;;AACA,kEAA0C;AAC1C,gDAAwB;AAExB,iEAA4D;AAC5D,wEAA+D;AAC/D,4DAAgE;AAChE,8CAAsB;AAEtB,MAAa,cAAe,SAAQ,yCAAkB;IAElD,YAAY,YAAoB,EAAE,QAAgB,EAAE,OAA6B;QAC7E,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAEzB,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;QAErC,MAAM,QAAQ,GAAa,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACpD,IAAI,WAAW,EAAE;YACb,QAAQ,CAAC,IAAI,CAAC,qBAAqB,WAAW,CAAC,WAAW,EAAE,CAAC,CAAC;SACjE;QAED,IAAI,CAAC,MAAM,GAAG,uBAAa,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE;YACrE,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC;YACtC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE;gBACrC,SAAS,EAAE,cAAI,CAAC,IAAI,CAAC,IAAA,2CAAiB,EAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,cAAc,CAAC;aACzE,CAAC;YACF,aAAa,EAAE,UAAU;YACzB,QAAQ;SACX,CAAC,CAAC;QAEH,IAAI,CAAC,WAAW,EAAE,CAAC;IACvB,CAAC;IAED,YAAY,CAAC,IAAa;QACtB,IAAI,CAAC,MA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/>
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import { EventEmitter } from "ws";
5
+ import { RpcMessage, RpcPeer } from "../../rpc";
6
+ import { RuntimeWorker, RuntimeWorkerOptions } from "./runtime-worker";
7
+ import worker_threads from "worker_threads";
8
+ export declare class NodeThreadWorker extends EventEmitter implements RuntimeWorker {
9
+ pluginId: string;
10
+ terminated: boolean;
11
+ worker: worker_threads.Worker;
12
+ constructor(mainFilename: string, pluginId: string, options: RuntimeWorkerOptions);
13
+ get pid(): number;
14
+ get stdout(): import("stream").Readable;
15
+ get stderr(): import("stream").Readable;
16
+ get killed(): boolean;
17
+ kill(): void;
18
+ send(message: RpcMessage, reject?: (e: Error) => void): void;
19
+ setupRpcPeer(peer: RpcPeer): void;
20
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NodeThreadWorker = void 0;
7
+ const ws_1 = require("ws");
8
+ const worker_threads_1 = __importDefault(require("worker_threads"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const plugin_npm_dependencies_1 = require("../plugin-npm-dependencies");
11
+ const v8_1 = __importDefault(require("v8"));
12
+ class NodeThreadWorker extends ws_1.EventEmitter {
13
+ pluginId;
14
+ terminated;
15
+ worker;
16
+ constructor(mainFilename, pluginId, options) {
17
+ super();
18
+ this.pluginId = pluginId;
19
+ const { env } = options;
20
+ this.worker = new worker_threads_1.default.Worker(mainFilename, {
21
+ argv: ['child-thread', this.pluginId],
22
+ env: Object.assign({}, process.env, env, {
23
+ NODE_PATH: path_1.default.join((0, plugin_npm_dependencies_1.getPluginNodePath)(this.pluginId), 'node_modules'),
24
+ }),
25
+ });
26
+ this.worker.on('exit', () => {
27
+ this.terminated = true;
28
+ this.emit('exit');
29
+ });
30
+ this.worker.on('error', e => {
31
+ this.emit('error', e);
32
+ });
33
+ this.worker.on('messageerror', e => {
34
+ this.emit('error', e);
35
+ });
36
+ }
37
+ get pid() {
38
+ return this.worker.threadId;
39
+ }
40
+ get stdout() {
41
+ return this.worker.stdout;
42
+ }
43
+ get stderr() {
44
+ return this.worker.stderr;
45
+ }
46
+ get killed() {
47
+ return this.terminated;
48
+ }
49
+ kill() {
50
+ if (!this.worker)
51
+ return;
52
+ this.worker.terminate();
53
+ this.worker.removeAllListeners();
54
+ this.worker.stdout.removeAllListeners();
55
+ this.worker.stderr.removeAllListeners();
56
+ this.worker = undefined;
57
+ }
58
+ send(message, reject) {
59
+ try {
60
+ if (!this.worker)
61
+ throw new Error('thread worker has been killed');
62
+ this.worker.postMessage(v8_1.default.serialize(message));
63
+ }
64
+ catch (e) {
65
+ reject?.(e);
66
+ }
67
+ }
68
+ setupRpcPeer(peer) {
69
+ this.worker.on('message', message => peer.handleMessage(v8_1.default.deserialize(message)));
70
+ }
71
+ }
72
+ exports.NodeThreadWorker = NodeThreadWorker;
73
+ //# sourceMappingURL=node-thread-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-thread-worker.js","sourceRoot":"","sources":["../../../src/plugin/runtime/node-thread-worker.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAkC;AAGlC,oEAA4C;AAC5C,gDAAwB;AACxB,wEAA+D;AAC/D,4CAAoB;AAEpB,MAAa,gBAAiB,SAAQ,iBAAY;IAIL;IAHzC,UAAU,CAAU;IACpB,MAAM,CAAwB;IAE9B,YAAY,YAAoB,EAAS,QAAgB,EAAE,OAA6B;QACpF,KAAK,EAAE,CAAC;QAD6B,aAAQ,GAAR,QAAQ,CAAQ;QAErD,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;QAExB,IAAI,CAAC,MAAM,GAAG,IAAI,wBAAc,CAAC,MAAM,CAAC,YAAY,EAAE;YAClD,IAAI,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC;YACrC,GAAG,EAAE,MAAM,CAAC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C,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC5B,CAAC;IAED,IAAI,CAAC,OAAmB,EAAE,MAA2B;QACjD,IAAI;YACA,IAAI,CAAC,IAAI,CAAC,MAAM;gBACZ,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;YACrD,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,YAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;SAClD;QACD,OAAO,CAAC,EAAE;YACN,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;SACf;IACL,CAAC;IAED,YAAY,CAAC,IAAa;QACtB,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,YAAE,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACtF,CAAC;CACJ;AAnED,4CAmEC"}
@@ -0,0 +1,10 @@
1
+ import { RpcMessage, RpcPeer } from "../../rpc";
2
+ import { createRpcDuplexSerializer } from '../../rpc-serializer';
3
+ import { ChildProcessWorker } from "./child-process-worker";
4
+ import { RuntimeWorkerOptions } from "./runtime-worker";
5
+ export declare class PythonRuntimeWorker extends ChildProcessWorker {
6
+ serializer: ReturnType<typeof createRpcDuplexSerializer>;
7
+ constructor(pluginId: string, options: RuntimeWorkerOptions);
8
+ setupRpcPeer(peer: RpcPeer): void;
9
+ send(message: RpcMessage, reject?: (e: Error) => void, serializationContext?: any): void;
10
+ }
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PythonRuntimeWorker = void 0;
7
+ const child_process_1 = __importDefault(require("child_process"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const os_1 = __importDefault(require("os"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const rpc_serializer_1 = require("../../rpc-serializer");
12
+ const child_process_worker_1 = require("./child-process-worker");
13
+ class PythonRuntimeWorker extends child_process_worker_1.ChildProcessWorker {
14
+ serializer;
15
+ constructor(pluginId, options) {
16
+ super(pluginId, options);
17
+ const { env, pluginDebug } = options;
18
+ const args = [
19
+ '-u',
20
+ ];
21
+ if (pluginDebug) {
22
+ args.push('-m', 'debugpy', '--listen', `0.0.0.0:${pluginDebug.inspectPort}`, '--wait-for-client');
23
+ }
24
+ args.push(path_1.default.join(__dirname, '../../../python', 'plugin_remote.py'));
25
+ const gstEnv = {};
26
+ // hack to fix gst plugin search path on mac...
27
+ if (os_1.default.platform() === 'darwin') {
28
+ const gstPaths = [
29
+ '/opt/homebrew/lib/gstreamer-1.0',
30
+ '/usr/local/lib/gstreamer-1.0',
31
+ ];
32
+ for (const gstPath of gstPaths) {
33
+ // search for common plugins.
34
+ if (fs_1.default.existsSync(path_1.default.join(gstPath, 'libgstx264.dylib'))
35
+ || fs_1.default.existsSync(path_1.default.join(gstPath, 'libgstlibav.dylib'))
36
+ || fs_1.default.existsSync(path_1.default.join(gstPath, 'libgstvideotestsrc.dylib'))) {
37
+ gstEnv['GST_PLUGIN_PATH'] = gstPath;
38
+ break;
39
+ }
40
+ }
41
+ }
42
+ let pythonPath = process.env.SCRYPTED_PYTHON_PATH;
43
+ if (os_1.default.platform() === 'win32') {
44
+ pythonPath ||= 'py.exe';
45
+ if (process.env.SCRYPTED_WINDOWS_PYTHON_VERSION)
46
+ args.unshift(process.env.SCRYPTED_WINDOWS_PYTHON_VERSION);
47
+ }
48
+ else {
49
+ pythonPath ||= 'python3';
50
+ }
51
+ args.push(this.pluginId);
52
+ const types = require.resolve('@scrypted/types');
53
+ const PYTHONPATH = types.substring(0, types.indexOf('types') + 'types'.length);
54
+ this.worker = child_process_1.default.spawn(pythonPath, args, {
55
+ // stdin, stdout, stderr, peer in, peer out
56
+ stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe'],
57
+ env: Object.assign({
58
+ PYTHONUNBUFFERED: '1',
59
+ PYTHONPATH,
60
+ }, gstEnv, process.env, env),
61
+ });
62
+ this.setupWorker();
63
+ }
64
+ setupRpcPeer(peer) {
65
+ const peerin = this.worker.stdio[3];
66
+ const peerout = this.worker.stdio[4];
67
+ const serializer = this.serializer = (0, rpc_serializer_1.createRpcDuplexSerializer)(peerin);
68
+ serializer.setupRpcPeer(peer);
69
+ peerout.on('data', data => serializer.onData(data));
70
+ peerin.on('error', e => {
71
+ this.emit('error', e);
72
+ serializer.onDisconnected();
73
+ });
74
+ peerout.on('error', e => {
75
+ this.emit('error', e);
76
+ serializer.onDisconnected();
77
+ });
78
+ }
79
+ send(message, reject, serializationContext) {
80
+ try {
81
+ if (!this.worker)
82
+ throw new Error('python worker has been killed');
83
+ this.serializer.sendMessage(message, reject, serializationContext);
84
+ }
85
+ catch (e) {
86
+ reject?.(e);
87
+ }
88
+ }
89
+ }
90
+ exports.PythonRuntimeWorker = PythonRuntimeWorker;
91
+ //# sourceMappingURL=python-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"python-worker.js","sourceRoot":"","sources":["../../../src/plugin/runtime/python-worker.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA0C;AAC1C,4CAAoB;AACpB,4CAAoB;AACpB,gDAAwB;AAGxB,yDAAiE;AACjE,iEAA4D;AAG5D,MAAa,mBAAoB,SAAQ,yCAAkB;IACvD,UAAU,CAA+C;IAEzD,YAAY,QAAgB,EAAE,OAA6B;QACvD,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAEzB,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;QACrC,MAAM,IAAI,GAAa;YACnB,IAAI;SACP,CAAC;QACF,IAAI,WAAW,EAAE;YACb,IAAI,CAAC,IAAI,CACL,IAAI,EACJ,SAAS,EACT,UAAU,EACV,WAAW,W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AAU,CAAC,cAAc,EAAE,CAAC;QAChC,CAAC,CAAC,CAAC;IACP,CAAC;IAED,IAAI,CAAC,OAAmB,EAAE,MAA2B,EAAE,oBAA0B;QAC7E,IAAI;YACA,IAAI,CAAC,IAAI,CAAC,MAAM;gBACZ,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;YACrD,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,oBAAoB,CAAC,CAAC;SACtE;QACD,OAAO,CAAC,EAAE;YACN,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;SACf;IACL,CAAC;CACJ;AA9FD,kDA8FC"}
@@ -0,0 +1,26 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import { RpcMessage, RpcPeer } from "../../rpc";
5
+ import { PluginDebug } from "../plugin-debug";
6
+ import { Readable } from "stream";
7
+ import net from "net";
8
+ export interface RuntimeWorkerOptions {
9
+ pluginDebug: PluginDebug;
10
+ env: any;
11
+ }
12
+ export interface RuntimeWorker {
13
+ pid: number;
14
+ stdout: Readable;
15
+ stderr: Readable;
16
+ killed: boolean;
17
+ kill(): void;
18
+ on(event: 'rpc', listener: (message: any, sendHandle: net.Socket) => void): this;
19
+ on(event: 'error', listener: (err: Error) => void): this;
20
+ on(event: 'close', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
21
+ on(event: 'disconnect', listener: () => void): this;
22
+ on(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
23
+ once(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
24
+ send(message: RpcMessage, reject?: (e: Error) => void, serializationContext?: any): void;
25
+ setupRpcPeer(peer: RpcPeer): void;
26
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=runtime-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-worker.js","sourceRoot":"","sources":["../../../src/plugin/runtime/runtime-worker.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { RpcSerializer } from "../rpc";
2
+ export declare class SidebandSocketSerializer implements RpcSerializer {
3
+ serialize(value: any, serializationContext?: any): void;
4
+ deserialize(serialized: any, serializationContext?: any): any;
5
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SidebandSocketSerializer = void 0;
4
+ class SidebandSocketSerializer {
5
+ serialize(value, serializationContext) {
6
+ if (!serializationContext)
7
+ throw new Error('socket serialization context unavailable');
8
+ serializationContext.sendHandle = value;
9
+ }
10
+ deserialize(serialized, serializationContext) {
11
+ if (!serializationContext)
12
+ throw new Error('socket deserialization context unavailable');
13
+ return serializationContext.sendHandle;
14
+ }
15
+ }
16
+ exports.SidebandSocketSerializer = SidebandSocketSerializer;
17
+ //# sourceMappingURL=socket-serializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socket-serializer.js","sourceRoot":"","sources":["../../src/plugin/socket-serializer.ts"],"names":[],"mappings":";;;AAEA,MAAa,wBAAwB;IACjC,SAAS,CAAC,KAAU,EAAE,oBAA0B;QAC5C,IAAI,CAAC,oBAAoB;YACrB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAChE,oBAAoB,CAAC,UAAU,GAAG,KAAK,CAAC;IAC5C,CAAC;IAED,WAAW,CAAC,UAAe,EAAE,oBAA0B;QACnD,IAAI,CAAC,oBAAoB;YACrB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAClE,OAAO,oBAAoB,CAAC,UAAU,CAAC;IAC3C,CAAC;CACJ;AAZD,4DAYC"}
@@ -0,0 +1,39 @@
1
+ import { EventListener, EventListenerOptions, EventListenerRegister, Logger, ScryptedDevice, ScryptedInterfaceDescriptor, ScryptedNativeId, SystemDeviceState, SystemManager } from "@scrypted/types";
2
+ import { EventRegistry } from "../event-registry";
3
+ import { getPropertyInterfaces } from "./descriptor";
4
+ import { PluginAPI } from "./plugin-api";
5
+ export declare class SystemManagerImpl implements SystemManager {
6
+ api: PluginAPI;
7
+ state: {
8
+ [id: string]: {
9
+ [property: string]: SystemDeviceState;
10
+ };
11
+ };
12
+ deviceProxies: {
13
+ [id: string]: ScryptedDevice;
14
+ };
15
+ log: Logger;
16
+ events: EventRegistry;
17
+ typesVersion: string;
18
+ descriptors: {
19
+ [scryptedInterface: string]: ScryptedInterfaceDescriptor;
20
+ };
21
+ propertyInterfaces: ReturnType<typeof getPropertyInterfaces>;
22
+ getDeviceState(id: string): {
23
+ [property: string]: SystemDeviceState;
24
+ };
25
+ getSystemState(): {
26
+ [id: string]: {
27
+ [property: string]: SystemDeviceState;
28
+ };
29
+ };
30
+ getDeviceById(idOrPluginId: string, nativeId?: ScryptedNativeId): any;
31
+ getDeviceByName(name: string): any;
32
+ listen(callback: EventListener): EventListenerRegister;
33
+ listenDevice(id: string, options: string | EventListenerOptions, callback: EventListener): EventListenerRegister;
34
+ removeDevice(id: string): Promise<void>;
35
+ getComponent(id: string): Promise<any>;
36
+ setScryptedInterfaceDescriptors(typesVersion: string, descriptors: {
37
+ [scryptedInterface: string]: ScryptedInterfaceDescriptor;
38
+ }): Promise<void>;
39
+ }