This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: restrict message sizes to 16kb (#147)
If the datachannel buffer grows to larger than 256kb it will close if you are using Chrome, so if it grows too large, wait for the `bufferedamountlow` event before continuing to send data. Also split data into 16kb while sending to ensure maximum cross browser compatibility. Fixes #144 Fixes #158 --------- Co-authored-by: Alex Potsides <alex@achingbrain.net>
- Loading branch information
1 parent
efe5ce7
commit aca4422
Showing
8 changed files
with
227 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,31 @@ | ||
import { WebRTCTransport } from './private-to-private/transport.js' | ||
import { WebRTCDirectTransport, type WebRTCDirectTransportComponents } from './private-to-public/transport.js' | ||
import { WebRTCDirectTransport, type WebRTCTransportDirectInit, type WebRTCDirectTransportComponents } from './private-to-public/transport.js' | ||
import type { WebRTCTransportComponents, WebRTCTransportInit } from './private-to-private/transport.js' | ||
import type { Transport } from '@libp2p/interface-transport' | ||
|
||
function webRTCDirect (): (components: WebRTCDirectTransportComponents) => Transport { | ||
return (components: WebRTCDirectTransportComponents) => new WebRTCDirectTransport(components) | ||
/** | ||
* @param {WebRTCTransportDirectInit} init - WebRTC direct transport configuration | ||
* @param init.dataChannel - DataChannel configurations | ||
* @param {number} init.dataChannel.maxMessageSize - Max message size that can be sent through the DataChannel. Larger messages will be chunked into smaller messages below this size (default 16kb) | ||
* @param {number} init.dataChannel.maxBufferedAmount - Max buffered amount a DataChannel can have (default 16mb) | ||
* @param {number} init.dataChannel.bufferedAmountLowEventTimeout - If max buffered amount is reached, this is the max time that is waited before the buffer is cleared (default 30 seconds) | ||
* @returns | ||
*/ | ||
function webRTCDirect (init?: WebRTCTransportDirectInit): (components: WebRTCDirectTransportComponents) => Transport { | ||
return (components: WebRTCDirectTransportComponents) => new WebRTCDirectTransport(components, init) | ||
} | ||
|
||
/** | ||
* @param {WebRTCTransportInit} init - WebRTC transport configuration | ||
* @param {RTCConfiguration} init.rtcConfiguration - RTCConfiguration | ||
* @param init.dataChannel - DataChannel configurations | ||
* @param {number} init.dataChannel.maxMessageSize - Max message size that can be sent through the DataChannel. Larger messages will be chunked into smaller messages below this size (default 16kb) | ||
* @param {number} init.dataChannel.maxBufferedAmount - Max buffered amount a DataChannel can have (default 16mb) | ||
* @param {number} init.dataChannel.bufferedAmountLowEventTimeout - If max buffered amount is reached, this is the max time that is waited before the buffer is cleared (default 30 seconds) | ||
* @returns | ||
*/ | ||
function webRTC (init?: WebRTCTransportInit): (components: WebRTCTransportComponents) => Transport { | ||
return (components: WebRTCTransportComponents) => new WebRTCTransport(components, init ?? {}) | ||
return (components: WebRTCTransportComponents) => new WebRTCTransport(components, init) | ||
} | ||
|
||
export { webRTC, webRTCDirect } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.