Skip to content

Commit

Permalink
コード整理
Browse files Browse the repository at this point in the history
  • Loading branch information
voluntas committed Feb 19, 2024
1 parent 395b9f6 commit 3a04cf9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
- run: rye run pytest tests/test_recvonly.py -s
- run: rye run pytest tests/test_messaging.py -s
- run: rye run pytest tests/test_openh264.py -s
- run: rye run pytest tests/test_vad.py -s
- name: Slack Notification
if: failure()
uses: rtCamp/action-slack-notify@v2
Expand Down
26 changes: 17 additions & 9 deletions tests/test_recvonly.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time
from threading import Event

from sora_sdk import Sora, SoraConnection
from sora_sdk import Sora, SoraConnection, SoraMediaTrack


class Recvonly:
Expand All @@ -18,31 +18,39 @@ class Recvonly:

def __init__(self, signaling_urls, channel_id, metadata):
self.sora = Sora()
self.connection = self.sora.create_connection(
self._connection = self.sora.create_connection(
signaling_urls=signaling_urls,
role="sendrecv",
channel_id=channel_id,
metadata=metadata,
)

self.connection.on_set_offer = self._on_set_offer
self.connection.on_notify = self._on_notify
self.connection.on_disconnect = self._on_disconnect
self._connection.on_set_offer = self._on_set_offer
self._connection.on_notify = self._on_notify
self._connection.on_disconnect = self._on_disconnect

self._connection.on_track = self._on_track

def connect(self):
self.connection.connect()
self._connection.connect()

# _connected が set されるまで 30 秒待つ
assert self._connected.wait(30)

return self

def _on_set_offer(self, raw_offer):
def _on_track(self, track: SoraMediaTrack):
if track.kind == "audio":
pass
if track.kind == "video":
pass

def _on_set_offer(self, raw_offer: str):
offer = json.loads(raw_offer)
if offer["type"] == "offer":
self._connection_id = offer["connection_id"]

def _on_notify(self, raw_message):
def _on_notify(self, raw_message: str):
message = json.loads(raw_message)
if (
message["type"] == "notify"
Expand All @@ -58,7 +66,7 @@ def _on_disconnect(self, error_code, message):
self._connected.clear()

def disconnect(self):
self.connection.disconnect()
self._connection.disconnect()


def test_recvonly(setup):
Expand Down

0 comments on commit 3a04cf9

Please sign in to comment.