From 4febf40ec69672b228b1ba7ff80d8a5375dff14d Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Fri, 18 Feb 2022 11:51:39 -0800 Subject: [PATCH] google-home: cast casting resolution at 960 width --- plugins/google-home/package-lock.json | 4 ++-- plugins/google-home/package.json | 2 +- plugins/google-home/src/main.ts | 17 ++++++++++------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/plugins/google-home/package-lock.json b/plugins/google-home/package-lock.json index f78c12469..f8e938733 100644 --- a/plugins/google-home/package-lock.json +++ b/plugins/google-home/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/google-home", - "version": "0.0.38", + "version": "0.0.39", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/google-home", - "version": "0.0.38", + "version": "0.0.39", "dependencies": { "@googleapis/homegraph": "^2.0.0", "@homebridge/ciao": "^1.1.3", diff --git a/plugins/google-home/package.json b/plugins/google-home/package.json index 2af221c96..57986b9d2 100644 --- a/plugins/google-home/package.json +++ b/plugins/google-home/package.json @@ -42,5 +42,5 @@ "@types/lodash": "^4.14.168", "@types/url-parse": "^1.4.3" }, - "version": "0.0.38" + "version": "0.0.39" } diff --git a/plugins/google-home/src/main.ts b/plugins/google-home/src/main.ts index 2fd1c0930..41f056a3e 100644 --- a/plugins/google-home/src/main.ts +++ b/plugins/google-home/src/main.ts @@ -1,4 +1,4 @@ -import { EngineIOHandler, HttpRequest, HttpRequestHandler, HttpResponse, MediaObject, MixinProvider, Refresh, RequestMediaStreamOptions, RTCAVMessage, RTCAVSignalingOfferSetup, ScryptedDevice, ScryptedDeviceBase, ScryptedDeviceType, ScryptedInterface, ScryptedInterfaceProperty, ScryptedMimeTypes } from '@scrypted/sdk'; +import { EngineIOHandler, HttpRequest, HttpRequestHandler, HttpResponse, MediaObject, MixinProvider, Refresh, RequestMediaStreamOptions, RTCAVMessage, RTCAVSignalingSetup, ScryptedDevice, ScryptedDeviceBase, ScryptedDeviceType, ScryptedInterface, ScryptedInterfaceProperty, ScryptedMimeTypes } from '@scrypted/sdk'; import sdk from '@scrypted/sdk'; import type { SmartHomeV1DisconnectRequest, SmartHomeV1DisconnectResponse, SmartHomeV1ExecuteRequest, SmartHomeV1ExecuteResponse, SmartHomeV1ExecuteResponseCommands } from 'actions-on-google/dist/service/smarthome/api/v1'; import { supportedTypes } from './common'; @@ -16,14 +16,14 @@ import { canAccess } from './commands/camerastream'; import { URL } from 'url'; import { homegraph } from '@googleapis/homegraph'; import type { JSONClient } from 'google-auth-library/build/src/auth/googleauth'; -import { addBuiltins, startRTCPeerConnection } from "../../../common/src/wrtc-convertors"; +import { addBuiltins, startRTCPeerConnection } from "../../../common/src/ffmpeg-to-wrtc"; import ciao, { Protocol } from '@homebridge/ciao'; const responder = ciao.getResponder(); const { systemManager, mediaManager, endpointManager, deviceManager } = sdk; -addBuiltins(console, mediaManager); +addBuiltins(mediaManager); function uuidv4() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { @@ -201,7 +201,7 @@ class GoogleHome extends ScryptedDeviceBase implements HttpRequestHandler, Engin return; } - let setup: RTCAVSignalingOfferSetup; + let setup: RTCAVSignalingSetup; const msos = await camera.getVideoStreamOptions(); const found = msos.find(mso => mso.container?.startsWith(ScryptedMimeTypes.RTCAVSignalingPrefix)) as RequestMediaStreamOptions; @@ -217,26 +217,29 @@ class GoogleHome extends ScryptedDeviceBase implements HttpRequestHandler, Engin const { offer } = json; const mo = mediaManager.createMediaObject(Buffer.from(JSON.stringify(offer)), ScryptedMimeTypes.RTCAVOffer) - const answer = await mediaManager.convertMediaObjectToBuffer(mo, setup.signalingMimeType); + const answer = await mediaManager.convertMediaObjectToBuffer(mo, undefined); ws.send(answer.toString()); } } else { setup = { + type: 'offer', audio: { direction: 'recvonly', }, video: { direction: 'recvonly', }, - signalingMimeType: undefined, } ws.onmessage = async (message) => { ws.onmessage = undefined; const json = JSON.parse(message.data as string); const { offer } = json; - const { pc, answer } = await startRTCPeerConnection(await camera.getVideoStream(), offer); + // chromecast and nest hub are super underpowered so cap the width + const { pc, answer } = await startRTCPeerConnection(await camera.getVideoStream(), offer, { + maxWidth: 960, + }); ws.send(JSON.stringify(answer)); } }