Skip to content

Commit

Permalink
remote: cleanup remote hint now that rebroadcast uses external by def…
Browse files Browse the repository at this point in the history
…ault (#594)
  • Loading branch information
bjia56 authored Mar 1, 2023
1 parent a89700a commit fa218cb
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions plugins/remote/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Device, DeviceProvider, DeviceCreator, DeviceCreatorSettings, ScryptedDevice, ScryptedDeviceBase, ScryptedDeviceType, ScryptedInterface, Setting, Settings, Battery, VideoCamera, SettingValue, RequestMediaStreamOptions, MediaObject, DeviceManifest} from '@scrypted/sdk';
import { Device, DeviceProvider, DeviceCreator, DeviceCreatorSettings, ScryptedDevice, ScryptedDeviceBase, ScryptedDeviceType, ScryptedInterface, Setting, Settings, Battery, SettingValue, DeviceManifest} from '@scrypted/sdk';
import sdk from '@scrypted/sdk';
import { StorageSettings } from '@scrypted/sdk/storage-settings';
import { connectScryptedClient, ScryptedClientStatic } from '@scrypted/client';
Expand Down Expand Up @@ -111,28 +111,15 @@ class ScryptedRemoteInstance extends ScryptedDeviceBase implements DeviceProvide
deviceManager.getDeviceState(device.nativeId).batteryLevel = (<Battery>remoteDevice).batteryLevel;
}

// since the remote may be using rebroadcast, explicitly request the external
// address for video streams
if (device.interfaces.includes(ScryptedInterface.VideoCamera)) {
const remoteGetVideoStream = (<VideoCamera><any>remoteDevice).getVideoStream;
(<VideoCamera><any>remoteDevice).getVideoStream = async (options?: RequestMediaStreamOptions): Promise<MediaObject> => {
if (!options) {
options = {};
}
(<any>options).route = "external";
return await remoteGetVideoStream(options);
}
}

// for device providers, we need to translate the nativeId
// for device providers, we intercept calls to load device representations
// stored within this plugin instance, instead of directly from the remote
if (device.interfaces.includes(ScryptedInterface.DeviceProvider)) {
const plugin = this;
(<DeviceProvider><any>remoteDevice).getDevice = async (nativeId: string): Promise<Device> => {
return <Device>plugin.devices.get(nativeId);
return <Device>this.devices.get(nativeId);
}
(<DeviceProvider><any>remoteDevice).releaseDevice = async (id: string, nativeId: string): Promise<any> => {
// don't delete the device from the remote
plugin.releaseDevice(id, nativeId);
this.releaseDevice(id, nativeId);
}
}
}
Expand Down

0 comments on commit fa218cb

Please sign in to comment.