Skip to content

Commit

Permalink
server: add hook for getting runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Apr 29, 2023
1 parent 01c7b56 commit e169d15
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions server/src/plugin/plugin-remote-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function startPluginRemote(mainFilename: string, pluginId: string, peerSe

let postInstallSourceMapSupport: (scrypted: ScryptedStatic) => void;

attachPluginRemote(peer, {
const scrypted = attachPluginRemote(peer, {
createMediaManager: async (sm, dm) => {
systemManager = sm;
deviceManager = dm
Expand Down Expand Up @@ -394,7 +394,11 @@ export function startPluginRemote(mainFilename: string, pluginId: string, peerSe
}).then(scrypted => {
systemManager = scrypted.systemManager;
deviceManager = scrypted.deviceManager as DeviceManagerImpl;
return scrypted;
});

return peer;
return {
peer,
scryptedPromise: scrypted,
};
}
8 changes: 6 additions & 2 deletions server/src/scrypted-plugin-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@ import { SidebandSocketSerializer } from "./plugin/socket-serializer";

function start(mainFilename: string) {
if (process.argv[2] === 'child-thread') {
const peer = startPluginRemote(mainFilename, process.argv[3], (message, reject) => {
const ret = startPluginRemote(mainFilename, process.argv[3], (message, reject) => {
try {
worker_threads.parentPort.postMessage(v8.serialize(message));
}
catch (e) {
reject?.(e);
}
});
const { peer } = ret;
peer.transportSafeArgumentTypes.add(Buffer.name);
peer.transportSafeArgumentTypes.add(Uint8Array.name);
worker_threads.parentPort.on('message', message => peer.handleMessage(v8.deserialize(message)));
return ret;
}
else {
const peer = startPluginRemote(mainFilename, process.argv[3], (message, reject, serializationContext) => process.send(message, serializationContext?.sendHandle, {
const ret = startPluginRemote(mainFilename, process.argv[3], (message, reject, serializationContext) => process.send(message, serializationContext?.sendHandle, {
swallowErrors: !reject,
}, e => {
if (e)
reject?.(e);
}));
const { peer } = ret;

peer.transportSafeArgumentTypes.add(Buffer.name);
peer.transportSafeArgumentTypes.add(Uint8Array.name);
Expand All @@ -35,6 +38,7 @@ function start(mainFilename: string) {
console.error('peer host disconnected, exiting.');
process.exit(1);
});
return ret;
}
}

Expand Down

0 comments on commit e169d15

Please sign in to comment.