RTCSctpTransport:maxMessageSize 属性
RTCSctpTransport 接口的只读属性 maxMessageSize 指示使用 RTCDataChannel.send() 方法可以发送的消息的最大尺寸。
值
一个整数值,表示使用 RTCDataChannel.send() 方法可以发送的消息的最大尺寸(以字节为单位)。
示例
此示例展示了如何根据最大消息大小将字符串拆分为足够小的部分进行发送。
js
// Function splits strings to a specified size and returns array.
function splitStringToMax(str, maxLength) {
const result = [];
let i = 0;
while (i < str.length) {
result.push(str.substring(i, i + maxLength));
i += maxLength;
}
return result;
}
const peerConnection = new RTCPeerConnection(options);
const channel = peerConnection.createDataChannel("chat");
channel.onopen = (event) => {
const maximumMessageSize = peerConnection.sctp.maxMessageSize;
const textToSend = "This is my possibly overly long string!";
splitStringToMax(textToSend, maximumMessageSize).forEach((elem) => {
channel.send(elem);
});
};
规范
| 规范 |
|---|
| WebRTC:浏览器中的实时通信 # dom-rtcsctptransport-maxmessagesize |
浏览器兼容性
加载中…