mirror of
https://github.com/koush/scrypted.git
synced 2026-03-01 00:42:28 +00:00
server: console fixes
This commit is contained in:
@@ -433,7 +433,8 @@ export function startPluginClusterWorker() {
|
||||
return ds?.id;
|
||||
}
|
||||
|
||||
const getConsole = (hook: (stdout: PassThrough, stderr: PassThrough) => Promise<void>, also?: Console, alsoPrefix?: string) => {
|
||||
const getConsole = (hook: (stdout: PassThrough, stderr: PassThrough) => Promise<void>,
|
||||
also?: Console, alsoPrefix?: string) => {
|
||||
|
||||
const stdout = new PassThrough();
|
||||
const stderr = new PassThrough();
|
||||
@@ -459,23 +460,27 @@ export function startPluginClusterWorker() {
|
||||
for (const m of methods) {
|
||||
const old = (ret as any)[m].bind(ret);
|
||||
(ret as any)[m] = (...args: any[]) => {
|
||||
(console as any)[m](...args);
|
||||
old(...args);
|
||||
|
||||
// prefer the mixin version for local/remote console dump.
|
||||
if (also && alsoPrefix && printers.includes(m)) {
|
||||
(also as any)[m](alsoPrefix, ...args);
|
||||
}
|
||||
else {
|
||||
(console as any)[m](...args);
|
||||
}
|
||||
// call through to old method to ensure it gets written
|
||||
// to log buffer.
|
||||
old(...args);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const getDeviceConsole = (nativeId?: ScryptedNativeId) => {
|
||||
const getDeviceConsole = (nativeId?: ScryptedNativeId, disableEcho?: boolean) => {
|
||||
return getConsole(async (stdout, stderr) => {
|
||||
stdout.on('data', data => events.emit('stdout', data, nativeId));
|
||||
stderr.on('data', data => events.emit('stderr', data, nativeId));
|
||||
});
|
||||
}, undefined, undefined);
|
||||
}
|
||||
|
||||
const getMixinConsole = (mixinId: string, nativeId?: ScryptedNativeId) => {
|
||||
|
||||
@@ -326,10 +326,15 @@ export function attachPluginRemote(peer: RpcPeer, options?: PluginRemoteAttachOp
|
||||
// JSON stringify over rpc turns undefined into null.
|
||||
if (nativeId === null)
|
||||
nativeId = undefined;
|
||||
deviceManager.nativeIds.set(nativeId?.toString(), {
|
||||
id,
|
||||
storage,
|
||||
});
|
||||
if (id) {
|
||||
deviceManager.nativeIds.set(nativeId?.toString(), {
|
||||
id,
|
||||
storage,
|
||||
});
|
||||
}
|
||||
else {
|
||||
deviceManager.nativeIds.delete(nativeId);
|
||||
}
|
||||
},
|
||||
|
||||
async updateDescriptor(id: string, state: { [property: string]: SystemDeviceState }) {
|
||||
|
||||
@@ -403,7 +403,7 @@ export class RpcPeer {
|
||||
if (rpcApply.method) {
|
||||
const method = target[rpcApply.method];
|
||||
if (!method)
|
||||
throw new Error(`target ${target?.constructor.name} does not have method ${rpcApply.method}`);
|
||||
throw new Error(`target ${target?.constructor?.name} does not have method ${rpcApply.method}`);
|
||||
value = await target[rpcApply.method](...args);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -539,12 +539,15 @@ export class ScryptedRuntime {
|
||||
}
|
||||
this.stateManager.removeDevice(device._id);
|
||||
|
||||
const plugin = this.plugins[device.pluginId];
|
||||
// remove the plugin too
|
||||
if (!device.nativeId) {
|
||||
const plugin = this.plugins[device.pluginId];
|
||||
plugin?.kill();
|
||||
await this.datastore.removeId(Plugin, device.pluginId);
|
||||
}
|
||||
else {
|
||||
await plugin.remote.setNativeId(device.nativeId, undefined, undefined);
|
||||
}
|
||||
}
|
||||
|
||||
upsertDevice(pluginId: string, device: Device, invalidate?: boolean): Promise<PluginDevice> {
|
||||
|
||||
Reference in New Issue
Block a user