forked from jamesdo/react-native-webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getDisplayMedia.js
33 lines (25 loc) · 892 Bytes
/
getDisplayMedia.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
import { Platform, NativeModules } from 'react-native';
import MediaStream from './MediaStream';
import MediaStreamError from './MediaStreamError';
const { WebRTCModule } = NativeModules;
export default function getDisplayMedia(constraints) {
if (!constraints || !constraints.video) {
return Promise.reject(new TypeError());
}
return new Promise((resolve, reject) => {
WebRTCModule.getDisplayMedia()
.then(data => {
const { streamId, track } = data;
const info = {
streamId: streamId,
streamReactTag: streamId,
tracks: [track]
};
const stream = new MediaStream(info);
resolve(stream);
}, error => {
reject(new MediaStreamError(error));
});
});
}