Skip to content

fix: dataconnection _buffer use javascript syntax #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/peerjs/dataconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _apply_options(
self._negotiator: Negotiator = None
self.stringify = lambda data: json.dumps(data)
self.parse = lambda jsn: json.loads(jsn)
self._buffer: []
self._buffer = []
self._bufferSize = 0
self._buffering = False
self._chunkedData = {}
Expand Down Expand Up @@ -287,8 +287,8 @@ async def send(self, data, chunked: bool = False) -> None:

async def _bufferedSend(self, msg: any) -> None:
if self._buffering or not await self._trySend(msg):
self._buffer.push(msg)
self._bufferSize = self._buffer.length
self._buffer.append(msg)
self._bufferSize = len(self._buffer)

async def _trySend(self, msg) -> bool:
"""Return true if the send succeeds."""
Expand Down Expand Up @@ -320,14 +320,14 @@ def _tryBuffer(self) -> None:
"""Try to send the first message in the buffer."""
if not self.open:
return
if self._buffer.length == 0:
if len(self._buffer) == 0:
return

msg = self._buffer[0]

if self._trySend(msg):
self._buffer.shift()
self._bufferSize = self._buffer.length
self._buffer.pop()
self._bufferSize = len(self._buffer)
self._tryBuffer()

# def _sendChunks(self, blob: Blob) -> None:
Expand Down