diff --git a/plugins/homekit/package-lock.json b/plugins/homekit/package-lock.json index dee7a4142..41f9dcd63 100644 --- a/plugins/homekit/package-lock.json +++ b/plugins/homekit/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/homekit", - "version": "0.0.280", + "version": "0.0.281", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/homekit", - "version": "0.0.280", + "version": "0.0.281", "dependencies": { "@koush/qrcode-terminal": "^0.12.0", "@koush/werift-src": "file:../../external/werift", diff --git a/plugins/homekit/package.json b/plugins/homekit/package.json index 2c767dd9f..e7117e5b8 100644 --- a/plugins/homekit/package.json +++ b/plugins/homekit/package.json @@ -45,5 +45,5 @@ "@types/node": "^14.17.9", "@types/url-parse": "^1.4.3" }, - "version": "0.0.280" + "version": "0.0.281" } diff --git a/plugins/homekit/src/types/camera/camera-streaming-session.ts b/plugins/homekit/src/types/camera/camera-streaming-session.ts index 520ef2e73..6cb01a359 100644 --- a/plugins/homekit/src/types/camera/camera-streaming-session.ts +++ b/plugins/homekit/src/types/camera/camera-streaming-session.ts @@ -27,9 +27,13 @@ export interface CameraStreamingSession { // macos 12.3 beta 1 // bug seems resolved: -// ios 15.5 gm // macos 12.4 + +// bug is still present: +// ios 15.5 RC export async function waitForFirstVideoRtcp(console: Console, session: CameraStreamingSession) { + if (!session.videoReturnRtcpReady) + return; console.log('Waiting for video RTCP packet before sending video.'); await session.videoReturnRtcpReady; console.log('Received first video RTCP packet.'); diff --git a/plugins/homekit/src/types/camera/camera-streaming.ts b/plugins/homekit/src/types/camera/camera-streaming.ts index f3fbca33a..d3973ccca 100644 --- a/plugins/homekit/src/types/camera/camera-streaming.ts +++ b/plugins/homekit/src/types/camera/camera-streaming.ts @@ -4,8 +4,10 @@ import { RtpPacket } from '@koush/werift-src/packages/rtp/src/rtp/rtp'; import { ProtectionProfileAes128CmHmacSha1_80 } from '@koush/werift-src/packages/rtp/src/srtp/const'; import { SrtcpSession } from '@koush/werift-src/packages/rtp/src/srtp/srtcp'; import { bindUdp, closeQuiet } from '@scrypted/common/src/listen-cluster'; +import { timeoutPromise } from '@scrypted/common/src/promise-utils'; import sdk, { Camera, FFmpegInput, Intercom, MediaStreamOptions, RequestMediaStreamOptions, ScryptedDevice, ScryptedInterface, ScryptedMimeTypes, VideoCamera, VideoCameraConfiguration } from '@scrypted/sdk'; import dgram, { SocketType } from 'dgram'; +import { once } from 'events'; import os from 'os'; import { AudioStreamingCodecType, CameraController, CameraStreamingDelegate, PrepareStreamCallback, PrepareStreamRequest, PrepareStreamResponse, StartStreamRequest, StreamingRequest, StreamRequestCallback, StreamRequestTypes } from '../../hap'; import type { HomeKitPlugin } from "../../main"; @@ -66,6 +68,16 @@ export function createCameraStreamingDelegate(device: ScryptedDevice & VideoCame closeQuiet(audioReturn); }); + const isHomeHub = homekitPlugin.storageSettings.values.lastKnownHomeHub?.includes(request.targetAddress); + if (isHomeHub) + console.log('Streaming request is coming from the active HomeHub. Will wait for initial RTCP packet.'); + + const videoReturnRtcpReady = !isHomeHub + ? undefined + : timeoutPromise(1000, once(videoReturn, 'message')).catch(() => { + console.warn('Video RTCP Packet timed out. There may be a network (routing/firewall) issue preventing the Apple device sending UDP packets back to Scrypted.'); + }); + const session: CameraStreamingSession = { aconfig: { keys: { @@ -94,15 +106,9 @@ export function createCameraStreamingDelegate(device: ScryptedDevice & VideoCame audiossrc, videoReturn, audioReturn, - videoReturnRtcpReady: Promise.resolve(undefined), - // waitForFirstVideoRtcp no longer seems necessary as of the GM release - // of ios 15.5 and macos 12.4 - // videoReturnRtcpReady: timeoutPromise(1000, once(videoReturn, 'message')).catch(() => { - // console.warn('Video RTCP Packet timed out. There may be a network (routing/firewall) issue preventing the Apple device sending UDP packets back to Scrypted.'); - // }), + videoReturnRtcpReady, }; - sessions.set(request.sessionID, session); const response: PrepareStreamResponse = { @@ -184,9 +190,10 @@ export function createCameraStreamingDelegate(device: ScryptedDevice & VideoCame session.startRequest = request as StartStreamRequest; - const forceLowBandwidth = homekitPlugin.storageSettings.values.lastKnownHomeHub?.includes(session.prepareRequest.targetAddress); - if (forceLowBandwidth) - console.log('Streaming request is coming from the active HomeHub. Low bandwidth stream will be selected in case this is a remote wifi connection.'); + // const forceLowBandwidth = homekitPlugin.storageSettings.values.lastKnownHomeHub?.includes(session.prepareRequest.targetAddress); + // if (forceLowBandwidth) + // console.log('Streaming request is coming from the active HomeHub. Low bandwidth stream will be selected in case this is a remote wifi connection.'); + const forceLowBandwidth = false; const { destination,