Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
import {NativeModules} from 'react-native';
import EventTarget from 'event-target-shim';
import getUserMedia from './getUserMedia';
const {WebRTCModule} = NativeModules;
const MEDIA_DEVICES_EVENTS = [
'devicechange'
];
class MediaDevices extends EventTarget(MEDIA_DEVICES_EVENTS) {
// TODO: implement.
ondevicechange: ?Function;
/**
* W3C "Media Capture and Streams" compatible {@code enumerateDevices}
* implementation.
*/
enumerateDevices() {
return new Promise(resolve => WebRTCModule.enumerateDevices(resolve));
}
/**
* W3C "Media Capture and Streams" compatible {@code getUserMedia}
* implementation.
* See: https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-enumeratedevices
*
'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;
'mute',
'unmute',
// see: https://www.w3.org/TR/mediacapture-streams/#constrainable-interface
'overconstrained',
];
type MediaStreamTrackState = "live" | "ended";
type SourceInfo = {
id: string;
label: string;
facing: string;
kind: string;
};
class MediaStreamTrack extends EventTarget(MEDIA_STREAM_TRACK_EVENTS) {
_enabled: boolean;
id: string;
kind: string;
label: string;
muted: boolean;
readonly: boolean; // how to decide?
// readyState in java: INITIALIZING, LIVE, ENDED, FAILED
readyState: MediaStreamTrackState;
remote: boolean;
onended: ?Function;
onmute: ?Function;
onunmute: ?Function;
overconstrained: ?Function;
constructor(info) {
'icecandidate',
'icecandidateerror',
'iceconnectionstatechange',
'icegatheringstatechange',
'negotiationneeded',
'signalingstatechange',
// Peer-to-peer Data API:
'datachannel',
// old:
'addstream',
'removestream',
];
let nextPeerConnectionId = 0;
export default class RTCPeerConnection extends EventTarget(PEER_CONNECTION_EVENTS) {
localDescription: RTCSessionDescription;
remoteDescription: RTCSessionDescription;
signalingState: RTCSignalingState = 'stable';
iceGatheringState: RTCIceGatheringState = 'new';
iceConnectionState: RTCIceConnectionState = 'new';
onconnectionstatechange: ?Function;
onicecandidate: ?Function;
onicecandidateerror: ?Function;
oniceconnectionstatechange: ?Function;
onicegatheringstatechange: ?Function;
onnegotiationneeded: ?Function;
onsignalingstatechange: ?Function;
onaddstream: ?Function;
import {NativeModules} from 'react-native';
import EventTarget from 'event-target-shim';
import uuid from 'uuid';
import MediaStreamTrack from './MediaStreamTrack';
const {WebRTCModule} = NativeModules;
const MEDIA_STREAM_EVENTS = [
'active',
'inactive',
'addtrack',
'removetrack',
];
export default class MediaStream extends EventTarget(MEDIA_STREAM_EVENTS) {
id: string;
active: boolean = true;
onactive: ?Function;
oninactive: ?Function;
onaddtrack: ?Function;
onremovetrack: ?Function;
_tracks: Array = [];
/**
* The identifier of this MediaStream unique within the associated
* WebRTCModule instance. As the id of a remote MediaStream instance is unique
* only within the associated RTCPeerConnection, it is not sufficiently unique
* to identify this MediaStream across multiple RTCPeerConnections and to
* unambiguously differentiate it from a local MediaStream instance not added
'icecandidate',
'iceconnectionstatechange',
'icegatheringstatechange',
'identityresult',
'idpassertionerror',
'idpvalidationerror',
'negotiationneeded',
'peeridentity',
'signalingstatechange',
'track',
];
/**
* @package
*/
export default class RTCPeerConnectionEventTarget extends EventTarget(PEER_CONNECTION_EVENTS) { }