代码拉取完成,页面将自动刷新
同步操作将从 mirrors_mattermost/react-native-webrtc 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
'use strict';
import {NativeModules, DeviceEventEmitter} from 'react-native';
import base64 from 'base64-js';
import EventTarget from 'event-target-shim';
import MessageEvent from './MessageEvent';
import RTCDataChannelEvent from './RTCDataChannelEvent';
const {WebRTCModule} = NativeModules;
type RTCDataChannelInit = {
ordered?: boolean;
maxPacketLifeTime?: number;
maxRetransmits?: number;
protocol?: string;
negotiated?: boolean;
id?: number;
// deprecated:
maxRetransmitTime?: number,
};
type RTCDataChannelState =
'connecting' |
'open' |
'closing' |
'closed';
const DATA_CHANNEL_EVENTS = [
'open',
'message',
'bufferedamountlow',
'close',
'error',
];
class ResourceInUse extends Error {}
export default class RTCDataChannel extends EventTarget(DATA_CHANNEL_EVENTS) {
_peerConnectionId: number;
binaryType: 'arraybuffer' = 'arraybuffer'; // we only support 'arraybuffer'
bufferedAmount: number = 0;
bufferedAmountLowThreshold: number = 0;
id: number;
label: string;
maxPacketLifeTime: ?number = null;
maxRetransmits: ?number = null;
negotiated: boolean = false;
ordered: boolean = true;
protocol: string = '';
readyState: RTCDataChannelState = 'connecting';
onopen: ?Function;
onmessage: ?Function;
onbufferedamountlow: ?Function;
onerror: ?Function;
onclose: ?Function;
constructor(
peerConnectionId: number,
label: string,
dataChannelDict: RTCDataChannelInit) {
super();
this._peerConnectionId = peerConnectionId;
this.label = label;
// The standard defines dataChannelDict as optional for
// RTCPeerConnection#createDataChannel and that is how we have implemented
// the method in question. However, the method will (1) allocate an
// RTCDataChannel.id if the caller has not specified a value and (2)
// pass it to RTCDataChannel's constructor via dataChannelDict.
// Consequently, dataChannelDict is not optional for RTCDataChannel's
// constructor.
this.id = ('id' in dataChannelDict) ? dataChannelDict.id : -1;
this.ordered = !!dataChannelDict.ordered;
this.maxPacketLifeTime = dataChannelDict.maxPacketLifeTime;
this.maxRetransmits = dataChannelDict.maxRetransmits;
this.protocol = dataChannelDict.protocol || '';
this.negotiated = !!dataChannelDict.negotiated;
this._registerEvents();
}
send(data: string | ArrayBuffer | ArrayBufferView) {
if (typeof data === 'string') {
WebRTCModule.dataChannelSend(this._peerConnectionId, this.id, data, 'text');
return;
}
// Safely convert the buffer object to an Uint8Array for base64-encoding
if (ArrayBuffer.isView(data)) {
data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
} else if (data instanceof ArrayBuffer) {
data = new Uint8Array(data);
} else {
throw new TypeError('Data must be either string, ArrayBuffer, or ArrayBufferView');
}
WebRTCModule.dataChannelSend(this._peerConnectionId, this.id, base64.fromByteArray(data), 'binary');
}
close() {
if (this.readyState === 'closing' || this.readyState === 'closed') {
return;
}
this.readyState = 'closing';
WebRTCModule.dataChannelClose(this._peerConnectionId, this.id);
}
_unregisterEvents() {
this._subscriptions.forEach(e => e.remove());
this._subscriptions = [];
}
_registerEvents() {
this._subscriptions = [
DeviceEventEmitter.addListener('dataChannelStateChanged', ev => {
if (ev.peerConnectionId !== this._peerConnectionId
|| ev.id !== this.id) {
return;
}
this.readyState = ev.state;
if (this.readyState === 'open') {
this.dispatchEvent(new RTCDataChannelEvent('open', {channel: this}));
} else if (this.readyState === 'close') {
this.dispatchEvent(new RTCDataChannelEvent('close', {channel: this}));
this._unregisterEvents();
}
}),
DeviceEventEmitter.addListener('dataChannelReceiveMessage', ev => {
if (ev.peerConnectionId !== this._peerConnectionId
|| ev.id !== this.id) {
return;
}
let data = ev.data;
if (ev.type === 'binary') {
data = base64.toByteArray(ev.data).buffer;
}
this.dispatchEvent(new MessageEvent('message', {data}));
}),
];
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。