|
16 | 16 |
|
17 | 17 | import asyncio |
18 | 18 | import json |
| 19 | +import weakref |
19 | 20 | from dataclasses import dataclass |
20 | 21 | from typing import TYPE_CHECKING, Any, AsyncIterator, Optional |
21 | 22 |
|
@@ -105,7 +106,9 @@ def __init__( |
105 | 106 | ``` |
106 | 107 | """ |
107 | 108 | self._track: Track | None = track |
108 | | - self._room: Room | None = room |
| 109 | + self._room_ref: "Optional[weakref.ref[Room]]" = ( |
| 110 | + weakref.ref(room) if room is not None else None |
| 111 | + ) |
109 | 112 | print("ROOM:", room) |
110 | 113 | self._sample_rate = sample_rate |
111 | 114 | self._num_channels = num_channels |
@@ -246,44 +249,33 @@ def from_track( |
246 | 249 | ) |
247 | 250 |
|
248 | 251 | def _set_room(self, room: Optional["Room"]) -> None: |
249 | | - self._room = room |
| 252 | + self._room_ref = weakref.ref(room) if room is not None else None |
250 | 253 | print("ROOM UPDATE:", room) |
251 | 254 |
|
252 | | - @property |
253 | | - def room(self) -> Optional["Room"]: |
254 | | - return self._room |
255 | | - |
256 | | - @property |
257 | | - def room_name(self) -> Optional[str]: |
258 | | - return self._room.name if self._room is not None else None |
259 | | - |
260 | | - @property |
261 | | - def participant_identity(self) -> Optional[str]: |
262 | | - pub = self._find_publication() |
263 | | - if pub is None: |
264 | | - return None |
265 | | - identity, _ = pub |
266 | | - return identity |
| 255 | + if self._processor: |
| 256 | + room = self._resolve_room() |
| 257 | + participant_identity, publication_sid = self._find_publication() or ("", "") |
| 258 | + self._processor._on_stream_info_updated( |
| 259 | + room_name=room.name if room is not None else "", # FIXME: default value? |
| 260 | + participant_identity=participant_identity, |
| 261 | + publication_sid=publication_sid, |
| 262 | + ) |
267 | 263 |
|
268 | | - @property |
269 | | - def publication_sid(self) -> Optional[str]: |
270 | | - pub = self._find_publication() |
271 | | - if pub is None: |
272 | | - return None |
273 | | - _, sid = pub |
274 | | - return sid |
| 264 | + def _resolve_room(self) -> Optional["Room"]: |
| 265 | + return self._room_ref() if self._room_ref is not None else None |
275 | 266 |
|
276 | 267 | def _find_publication(self) -> Optional[tuple[str, str]]: |
277 | | - if self._room is None or self._track is None: |
| 268 | + room = self._resolve_room() |
| 269 | + if room is None or self._track is None: |
278 | 270 | return None |
279 | 271 | track_sid = self._track.sid |
280 | 272 | if not track_sid: |
281 | 273 | return None |
282 | | - for participant in self._room.remote_participants.values(): |
| 274 | + for participant in room.remote_participants.values(): |
283 | 275 | publication = participant.track_publications.get(track_sid) |
284 | 276 | if publication is not None: |
285 | 277 | return participant.identity, publication.sid |
286 | | - local = self._room._local_participant |
| 278 | + local = room._local_participant |
287 | 279 | if local is not None: |
288 | 280 | for publication in local.track_publications.values(): |
289 | 281 | if publication.sid == track_sid: |
|
0 commit comments