Skip to content

Commit b05c12e

Browse files
committed
format
1 parent 25e6410 commit b05c12e

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

livekit-rtc/livekit/rtc/chat.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@
1919
from typing import Any, Dict, Literal, Optional
2020
import asyncio
2121

22-
from .room import Room, Participant, DataPacket, TextStreamReader, RemoteParticipant, LocalParticipant
22+
from .room import (
23+
Room,
24+
Participant,
25+
DataPacket,
26+
TextStreamReader,
27+
RemoteParticipant,
28+
LocalParticipant,
29+
)
2330
from .event_emitter import EventEmitter
2431
from ._utils import generate_random_base62
2532

@@ -101,16 +108,27 @@ def _on_data_received(self, dp: DataPacket):
101108
self.emit("message_received", msg)
102109
except Exception as e:
103110
logging.warning("failed to parse chat message: %s", e, exc_info=e)
104-
105-
def _on_text_stream_received(self, stream: TextStreamReader, participant_identity: str):
106-
task = asyncio.create_task(self._handle_text_stream(stream, participant_identity))
111+
112+
def _on_text_stream_received(
113+
self, stream: TextStreamReader, participant_identity: str
114+
):
115+
task = asyncio.create_task(
116+
self._handle_text_stream(stream, participant_identity)
117+
)
107118
self._tasks.append(task)
108119
task.add_done_callback(self._tasks.remove)
109120

110-
async def _handle_text_stream(self, stream: TextStreamReader, participant_identity: str):
121+
async def _handle_text_stream(
122+
self, stream: TextStreamReader, participant_identity: str
123+
):
111124
msg = await ChatMessage.from_text_stream(stream)
112-
participant: RemoteParticipant | LocalParticipant | None = self._room._remote_participants.get(participant_identity)
113-
if participant is None and self._room.local_participant.identity == participant_identity:
125+
participant: RemoteParticipant | LocalParticipant | None = (
126+
self._room._remote_participants.get(participant_identity)
127+
)
128+
if (
129+
participant is None
130+
and self._room.local_participant.identity == participant_identity
131+
):
114132
participant = self._room.local_participant
115133
msg.is_local = True
116134
msg.participant = participant
@@ -157,13 +175,13 @@ def asjsondict(self):
157175
if self.deleted:
158176
d["deleted"] = True
159177
return d
160-
178+
161179
@classmethod
162180
async def from_text_stream(cls, stream: TextStreamReader):
163181
message_text = await stream.read_all()
164182
timestamp = datetime.fromtimestamp(stream.info.timestamp / 1000.0)
165183
return cls(
166-
message=message_text,
167-
timestamp=timestamp,
168-
id=stream.info.stream_id,
184+
message=message_text,
185+
timestamp=timestamp,
186+
id=stream.info.stream_id,
169187
)

0 commit comments

Comments
 (0)