A shim to insulate apps from WebRTC spec changes and browser prefix differences
Overall
score
98%
Build a utility that helps developers safely send large messages over WebRTC data channels by determining the maximum safe message size and chunking oversized messages accordingly.
WebRTC data channels have browser-specific limitations on message sizes. Different browsers support different maximum message sizes, and these limits can vary based on browser versions and what the remote peer supports. Attempting to send messages that exceed these limits will cause errors.
Create a module that provides the following functionality:
Your implementation should:
getMaxMessageSize(peerConnection) returns a positive number representing the maximum safe message size in bytes @testcanSendMessage(peerConnection, message) returns true @testcanSendMessage(peerConnection, message) returns false @testchunkMessage(message, maxSize) returns an array of chunks where each chunk is at or under the specified size @test@generates
/**
* Get the maximum safe message size for a peer connection's data channels
* @param {RTCPeerConnection} peerConnection - The peer connection to check
* @returns {number} Maximum message size in bytes
*/
function getMaxMessageSize(peerConnection) {}
/**
* Check if a message can be sent safely through a data channel
* @param {RTCPeerConnection} peerConnection - The peer connection to check
* @param {string|ArrayBuffer|Uint8Array} message - The message to check
* @returns {boolean} True if message can be sent safely
*/
function canSendMessage(peerConnection, message) {}
/**
* Split a message into chunks of safe size
* @param {string|ArrayBuffer|Uint8Array} message - The message to chunk
* @param {number} maxSize - Maximum size per chunk in bytes
* @returns {Array<string|Uint8Array>} Array of message chunks
*/
function chunkMessage(message, maxSize) {}
module.exports = {
getMaxMessageSize,
canSendMessage,
chunkMessage
};Provides cross-browser WebRTC compatibility and data channel capabilities.
Install with Tessl CLI
npx tessl i tessl/npm-webrtc-adapterdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10