From 73b6aaa613bbefa81451cb05007d9e4a64a2e7e4 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sun, 1 Jan 2023 21:12:58 -0800 Subject: [PATCH] sdk/core/ring: restrict microphone request hackery to safari/ring only --- common/src/rtc-signaling.ts | 19 ++++++++++++++----- plugins/core/package-lock.json | 4 ++-- plugins/core/package.json | 2 +- plugins/ring/package-lock.json | 4 ++-- plugins/ring/package.json | 2 +- plugins/ring/src/main.ts | 1 + sdk/package-lock.json | 4 ++-- sdk/package.json | 2 +- sdk/types/package-lock.json | 4 ++-- sdk/types/package.json | 2 +- sdk/types/src/types.input.ts | 8 ++++++-- 11 files changed, 33 insertions(+), 19 deletions(-) diff --git a/common/src/rtc-signaling.ts b/common/src/rtc-signaling.ts index bb88aee4f..46b555561 100644 --- a/common/src/rtc-signaling.ts +++ b/common/src/rtc-signaling.ts @@ -137,13 +137,22 @@ export class BrowserSignalingSession implements RTCSignalingSession { } if (setup.audio) { - const audio = pc.addTransceiver('audio', setup.audio); - if (setup.audio.direction === 'sendrecv' || setup.audio.direction === 'sendonly') { - // offering a sendrecv on safari requires a mic be attached, or it fails to connect, + let audio: RTCRtpTransceiver; + if (setup.getUserMediaSafariHack && navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome')) { + // offering a sendrecv on safari requires a mic be attached for ring webrtc, or it fails to stream? // even if a silent track is used... - if (setup.type === 'offer' && navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome')) - await navigator.mediaDevices.getUserMedia({ audio: true }) + audio = pc.addTransceiver('audio', { + ...setup.audio, + streams: [ + await navigator.mediaDevices.getUserMedia({ audio: true }) + ], + }); + } + else { + audio = pc.addTransceiver('audio', setup.audio); + } + if (setup.audio.direction === 'sendrecv' || setup.audio.direction === 'sendonly') { this.microphone = audio.sender; } } diff --git a/plugins/core/package-lock.json b/plugins/core/package-lock.json index 2e3dd842e..3ee300786 100644 --- a/plugins/core/package-lock.json +++ b/plugins/core/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/core", - "version": "0.1.78", + "version": "0.1.80", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/core", - "version": "0.1.78", + "version": "0.1.80", "license": "Apache-2.0", "dependencies": { "@scrypted/common": "file:../../common", diff --git a/plugins/core/package.json b/plugins/core/package.json index 1b6895c7b..7df8f738b 100644 --- a/plugins/core/package.json +++ b/plugins/core/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/core", - "version": "0.1.78", + "version": "0.1.80", "description": "Scrypted Core plugin. Provides the UI, websocket, and engine.io APIs.", "author": "Scrypted", "license": "Apache-2.0", diff --git a/plugins/ring/package-lock.json b/plugins/ring/package-lock.json index bbc78fc35..3e116d51c 100644 --- a/plugins/ring/package-lock.json +++ b/plugins/ring/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/ring", - "version": "0.0.91", + "version": "0.0.92", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/ring", - "version": "0.0.91", + "version": "0.0.92", "dependencies": { "@koush/ring-client-api": "file:../../external/ring-client-api", "@scrypted/common": "file:../../common", diff --git a/plugins/ring/package.json b/plugins/ring/package.json index e4c407cbe..279a24379 100644 --- a/plugins/ring/package.json +++ b/plugins/ring/package.json @@ -44,5 +44,5 @@ "got": "11.8.2", "socket.io-client": "^2.4.0" }, - "version": "0.0.91" + "version": "0.0.92" } diff --git a/plugins/ring/src/main.ts b/plugins/ring/src/main.ts index 93fae777d..ebced31fd 100644 --- a/plugins/ring/src/main.ts +++ b/plugins/ring/src/main.ts @@ -441,6 +441,7 @@ class RingCameraDevice extends ScryptedDeviceBase implements DeviceProvider, Cam video: { direction: 'recvonly', }, + getUserMediaSafariHack: true, }, { createLocalDescription: async (type: 'offer' | 'answer', setup: RTCAVSignalingSetup, sendIceCandidate: RTCSignalingSendIceCandidate) => { if (type !== 'answer') diff --git a/sdk/package-lock.json b/sdk/package-lock.json index 17eb09282..6a8eff57c 100644 --- a/sdk/package-lock.json +++ b/sdk/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/sdk", - "version": "0.2.49", + "version": "0.2.51", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/sdk", - "version": "0.2.49", + "version": "0.2.51", "license": "ISC", "dependencies": { "@babel/preset-typescript": "^7.18.6", diff --git a/sdk/package.json b/sdk/package.json index d27109041..9d8cd5a42 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/sdk", - "version": "0.2.49", + "version": "0.2.51", "description": "", "main": "dist/src/index.js", "exports": { diff --git a/sdk/types/package-lock.json b/sdk/types/package-lock.json index 881a7d7ea..055b31ce4 100644 --- a/sdk/types/package-lock.json +++ b/sdk/types/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/types", - "version": "0.2.46", + "version": "0.2.48", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/types", - "version": "0.2.46", + "version": "0.2.48", "license": "ISC", "devDependencies": { "@types/rimraf": "^3.0.2", diff --git a/sdk/types/package.json b/sdk/types/package.json index 87b284a8f..72007a819 100644 --- a/sdk/types/package.json +++ b/sdk/types/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/types", - "version": "0.2.46", + "version": "0.2.48", "description": "", "main": "dist/index.js", "author": "", diff --git a/sdk/types/src/types.input.ts b/sdk/types/src/types.input.ts index b3c92d149..1fa4c3fed 100644 --- a/sdk/types/src/types.input.ts +++ b/sdk/types/src/types.input.ts @@ -1851,8 +1851,12 @@ export interface RTCAVSignalingSetup { * Mechanism to allow configuration of TURN/STUN servers, etc. */ configuration?: RTCConfiguration; - audio: RTCRtpTransceiverInit; - video: RTCRtpTransceiverInit; + audio?: RTCRtpTransceiverInit; + video?: RTCRtpTransceiverInit; + /** + * Some endpoints like Ring do not stream to Safari unless getUserMedia is called. Unclear why. + */ + getUserMediaSafariHack?: boolean; datachannel?: { label: string; dict?: RTCDataChannelInit;