Skip to content

Commit

Permalink
wait for sdp response before sending candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
bjia56 committed Dec 23, 2022
1 parent 909341b commit 93fe99b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions plugins/arlo/src/arlo_plugin/camera.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import asyncio
import json
import threading

import scrypted_sdk
from scrypted_sdk import ScryptedDeviceBase
from scrypted_sdk.types import Camera, VideoCamera, Intercom, MotionSensor, Battery, DeviceProvider, ScryptedDevice, ScryptedMimeTypes, ScryptedInterface, ScryptedDeviceType

from .logging import ScryptedDeviceLoggerMixin


class ArloCamera(ScryptedDeviceBase, Camera, VideoCamera, Intercom, MotionSensor, Battery, DeviceProvider, ScryptedDeviceLoggerMixin):
timeout = 30
nativeId = None
Expand Down Expand Up @@ -138,6 +137,7 @@ def _update_device_details(self, arlo_device):
"""
self.batteryLevel = arlo_device["properties"].get("batteryLevel")


class ArloCameraSpeaker(ScryptedDeviceBase, ScryptedDevice, ScryptedDeviceLoggerMixin):
def __init__(self, nativeId, arlo_device, arlo_basestation, provider):
super().__init__(nativeId=nativeId)
Expand Down Expand Up @@ -215,8 +215,14 @@ async def startRTCSignalingSession(self, session):
}

async def on_ice_candidate(candidate):
self.logger.info(f"Arlo offer candidate: {candidate.candidate}")
self.provider.arlo.NotifyPushToTalkCandidate(self.arlo_basestation, self.arlo_device, session_id, candidate.candidate)
try:
while not self.rtc_answered:
await asyncio.sleep(0.01)
self.logger.info(f"Arlo offer candidate: {candidate['candidate']}")
self.provider.arlo.NotifyPushToTalkCandidate(self.arlo_basestation, self.arlo_device, session_id, candidate['candidate'])
self.logger.info("Candidate sent")
except Exception as e:
self.logger.error(e)

offer = await session.createLocalDescription("offer", self.rtc_setup, on_ice_candidate)
self.logger.info(f"Arlo offer sdp:\n{offer['sdp']}")
Expand All @@ -236,6 +242,7 @@ def close(self):
self.rtc_setup = None
self.rtc_answered = False


class ArloCameraSpeakerSessionControl:
def __init__(self, speaker):
self.speaker = speaker
Expand Down

0 comments on commit 93fe99b

Please sign in to comment.