Skip to content

Commit

Permalink
remote: add reconnect and disable WIP mediaobject converter (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjia56 committed Mar 18, 2023
1 parent aefe4b6 commit 6b1794d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
12 changes: 6 additions & 6 deletions plugins/remote/package-lock.json

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

20 changes: 14 additions & 6 deletions plugins/remote/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ class ScryptedRemoteInstance extends ScryptedDeviceBase implements DeviceProvide
},
});

fromMimeType: string = ""
toMimeType: string = ""

constructor(nativeId: string) {
super(nativeId);
this.clearTryDiscoverDevices();


this.fromMimeType = 'x-scrypted-remote/x-media-object-' + this.id;
this.toMimeType = ScryptedMimeTypes.MediaObject;
this.toMimeType = '*';
sdk.mediaManager.addConverter(this);
}


Expand Down Expand Up @@ -193,9 +197,11 @@ class ScryptedRemoteInstance extends ScryptedDeviceBase implements DeviceProvide
});

this.client.onClose = () => {
this.console.log('client killed')
this.console.log('client killed, reconnecting in 60s');
setTimeout(async () => await this.clearTryDiscoverDevices(), 60000);
}

/* bjia56: since the MediaObject conversion isn't completely implemented, disable this for now
const { rpcPeer } = this.client;
const map = new WeakMap<RemoteMediaObject, MediaObject>();
rpcPeer.nameDeserializerMap.set('MediaObject', {
Expand All @@ -215,11 +221,13 @@ class ScryptedRemoteInstance extends ScryptedDeviceBase implements DeviceProvide
return rmo;
},
});
*/

this.console.log(`Connected to remote Scrypted server. Remote server version: ${this.client.serverVersion}`)
}

async convert(data: RemoteMediaObject, fromMimeType: string, toMimeType: string, options?: MediaObjectOptions): Promise<any> {
if (toMimeType === 'x-scrypted-remote/x-media-object')
if (toMimeType.startsWith('x-scrypted-remote/x-media-object'))
return data;
let ret = await this.client.mediaManager.convertMediaObject(data, toMimeType);
if (toMimeType === ScryptedMimeTypes.FFmpegInput) {
Expand Down Expand Up @@ -298,9 +306,9 @@ class ScryptedRemoteInstance extends ScryptedDeviceBase implements DeviceProvide

// first register the top level devices, then register the remaining
// devices by provider id
await deviceManager.onDevicesChanged(<DeviceManifest>{
devices: providerDeviceMap.get(this.nativeId),
providerNativeId: this.nativeId,
// top level devices are discovered one by one to avoid clobbering
providerDeviceMap.get(this.nativeId).map(async device => {
await deviceManager.onDeviceDiscovered(device);
});
for (let [providerNativeId, devices] of providerDeviceMap) {
await deviceManager.onDevicesChanged(<DeviceManifest>{
Expand Down

0 comments on commit 6b1794d

Please sign in to comment.