@techsee/techsee-media-service 999.1.0-vidu → 999.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -28
- package/lib/LocalStreamManager.d.ts +2 -1
- package/lib/LocalStreamManager.d.ts.map +1 -1
- package/lib/LocalStreamManager.js +91 -83
- package/lib/LocalStreamManager.js.map +1 -1
- package/lib/MediaConstants.d.ts +26 -2
- package/lib/MediaConstants.d.ts.map +1 -1
- package/lib/MediaConstants.js +39 -10
- package/lib/MediaConstants.js.map +1 -1
- package/lib/MediaContracts.d.ts +23 -12
- package/lib/MediaContracts.d.ts.map +1 -1
- package/lib/MediaContracts.js +1 -4
- package/lib/MediaContracts.js.map +1 -1
- package/lib/MediaPublisher.d.ts +4 -3
- package/lib/MediaPublisher.d.ts.map +1 -1
- package/lib/MediaPublisher.js +11 -13
- package/lib/MediaPublisher.js.map +1 -1
- package/lib/MediaServiceBase.d.ts +16 -8
- package/lib/MediaServiceBase.d.ts.map +1 -1
- package/lib/MediaServiceBase.js +213 -203
- package/lib/MediaServiceBase.js.map +1 -1
- package/lib/MediaSession/MediaServer.d.ts +8 -4
- package/lib/MediaSession/MediaServer.d.ts.map +1 -1
- package/lib/MediaSession/MediaServer.js +185 -112
- package/lib/MediaSession/MediaServer.js.map +1 -1
- package/lib/MediaSession/MediaSessionBase.d.ts +11 -1
- package/lib/MediaSession/MediaSessionBase.d.ts.map +1 -1
- package/lib/MediaSession/MediaSessionBase.js +48 -25
- package/lib/MediaSession/MediaSessionBase.js.map +1 -1
- package/lib/MediaSession/SessionOpentok.d.ts +12 -10
- package/lib/MediaSession/SessionOpentok.d.ts.map +1 -1
- package/lib/MediaSession/SessionOpentok.js +122 -121
- package/lib/MediaSession/SessionOpentok.js.map +1 -1
- package/lib/MediaSession/SessionTurn.d.ts +3 -1
- package/lib/MediaSession/SessionTurn.d.ts.map +1 -1
- package/lib/MediaSession/SessionTurn.js +124 -145
- package/lib/MediaSession/SessionTurn.js.map +1 -1
- package/lib/MediaSession/TurnConstants.d.ts +1 -0
- package/lib/MediaSession/TurnConstants.d.ts.map +1 -1
- package/lib/MediaSession/TurnConstants.js +2 -16
- package/lib/MediaSession/TurnConstants.js.map +1 -1
- package/lib/MediaSubscriber.d.ts +12 -11
- package/lib/MediaSubscriber.d.ts.map +1 -1
- package/lib/MediaSubscriber.js +49 -54
- package/lib/MediaSubscriber.js.map +1 -1
- package/lib/MediaUtils/Compatibility.d.ts +5 -1
- package/lib/MediaUtils/Compatibility.d.ts.map +1 -1
- package/lib/MediaUtils/Compatibility.js +80 -33
- package/lib/MediaUtils/Compatibility.js.map +1 -1
- package/lib/MediaUtils/MediaDomUtils.d.ts +6 -3
- package/lib/MediaUtils/MediaDomUtils.d.ts.map +1 -1
- package/lib/MediaUtils/MediaDomUtils.js +72 -60
- package/lib/MediaUtils/MediaDomUtils.js.map +1 -1
- package/lib/MediaUtils/MediaTracer.d.ts +1 -0
- package/lib/MediaUtils/MediaTracer.d.ts.map +1 -1
- package/lib/MediaUtils/MediaTracer.js +3 -5
- package/lib/MediaUtils/MediaTracer.js.map +1 -1
- package/lib/MediaUtils/index.d.ts +2 -0
- package/lib/MediaUtils/index.d.ts.map +1 -0
- package/lib/MediaUtils/index.js +6 -0
- package/lib/MediaUtils/index.js.map +1 -0
- package/lib/MultiParty/DetectWebRtcService.d.ts +19 -0
- package/lib/MultiParty/DetectWebRtcService.d.ts.map +1 -0
- package/lib/MultiParty/DetectWebRtcService.js +107 -0
- package/lib/MultiParty/DetectWebRtcService.js.map +1 -0
- package/lib/MultiParty/MediaCapabilitiesService.d.ts +18 -0
- package/lib/MultiParty/MediaCapabilitiesService.d.ts.map +1 -0
- package/lib/MultiParty/MediaCapabilitiesService.js +158 -0
- package/lib/MultiParty/MediaCapabilitiesService.js.map +1 -0
- package/lib/MultiParty/MediaCapabilitiesUtils.d.ts +6 -0
- package/lib/MultiParty/MediaCapabilitiesUtils.d.ts.map +1 -0
- package/lib/MultiParty/MediaCapabilitiesUtils.js +123 -0
- package/lib/MultiParty/MediaCapabilitiesUtils.js.map +1 -0
- package/lib/MultiParty/MediaTracer.d.ts +4 -0
- package/lib/MultiParty/MediaTracer.d.ts.map +1 -0
- package/lib/MultiParty/MediaTracer.js +10 -0
- package/lib/MultiParty/MediaTracer.js.map +1 -0
- package/lib/MultiParty/MultiPartyService.d.ts +49 -0
- package/lib/MultiParty/MultiPartyService.d.ts.map +1 -0
- package/lib/MultiParty/MultiPartyService.js +30 -0
- package/lib/MultiParty/MultiPartyService.js.map +1 -0
- package/lib/MultiParty/MultiPartyServiceFactory.d.ts +4 -0
- package/lib/MultiParty/MultiPartyServiceFactory.d.ts.map +1 -0
- package/lib/MultiParty/MultiPartyServiceFactory.js +13 -0
- package/lib/MultiParty/MultiPartyServiceFactory.js.map +1 -0
- package/lib/MultiParty/MultipartyServiceEventTypes.d.ts +89 -0
- package/lib/MultiParty/MultipartyServiceEventTypes.d.ts.map +1 -0
- package/lib/MultiParty/MultipartyServiceEventTypes.js +16 -0
- package/lib/MultiParty/MultipartyServiceEventTypes.js.map +1 -0
- package/lib/MultiParty/index.d.ts +7 -0
- package/lib/MultiParty/index.d.ts.map +1 -0
- package/lib/MultiParty/index.js +25 -0
- package/lib/MultiParty/index.js.map +1 -0
- package/lib/MultiParty/opentok/OpentokMultiPartyService.d.ts +38 -0
- package/lib/MultiParty/opentok/OpentokMultiPartyService.d.ts.map +1 -0
- package/lib/MultiParty/opentok/OpentokMultiPartyService.js +492 -0
- package/lib/MultiParty/opentok/OpentokMultiPartyService.js.map +1 -0
- package/lib/MultiParty/opentok/OpentokPublisher.d.ts +34 -0
- package/lib/MultiParty/opentok/OpentokPublisher.d.ts.map +1 -0
- package/lib/MultiParty/opentok/OpentokPublisher.js +121 -0
- package/lib/MultiParty/opentok/OpentokPublisher.js.map +1 -0
- package/lib/MultiParty/opentok/OpentokPublisherEventMapper.d.ts +20 -0
- package/lib/MultiParty/opentok/OpentokPublisherEventMapper.d.ts.map +1 -0
- package/lib/MultiParty/opentok/OpentokPublisherEventMapper.js +49 -0
- package/lib/MultiParty/opentok/OpentokPublisherEventMapper.js.map +1 -0
- package/lib/MultiParty/opentok/OpentokScreenPublisher.d.ts +6 -0
- package/lib/MultiParty/opentok/OpentokScreenPublisher.d.ts.map +1 -0
- package/lib/MultiParty/opentok/OpentokScreenPublisher.js +48 -0
- package/lib/MultiParty/opentok/OpentokScreenPublisher.js.map +1 -0
- package/lib/MultiParty/opentok/OpentokSubscriber.d.ts +2 -0
- package/lib/MultiParty/opentok/OpentokSubscriber.d.ts.map +1 -0
- package/lib/MultiParty/opentok/OpentokSubscriber.js +26 -0
- package/lib/MultiParty/opentok/OpentokSubscriber.js.map +1 -0
- package/lib/MultiParty/opentok/OpentokVideoPublisher.d.ts +19 -0
- package/lib/MultiParty/opentok/OpentokVideoPublisher.d.ts.map +1 -0
- package/lib/MultiParty/opentok/OpentokVideoPublisher.js +182 -0
- package/lib/MultiParty/opentok/OpentokVideoPublisher.js.map +1 -0
- package/lib/MultiParty/opentok/trace.d.ts +3 -0
- package/lib/MultiParty/opentok/trace.d.ts.map +1 -0
- package/lib/MultiParty/opentok/trace.js +18 -0
- package/lib/MultiParty/opentok/trace.js.map +1 -0
- package/lib/MultiParty/opentok.d.ts +463 -0
- package/lib/MultiParty/types.d.ts +33 -0
- package/lib/MultiParty/types.d.ts.map +1 -0
- package/lib/MultiParty/types.js +3 -0
- package/lib/MultiParty/types.js.map +1 -0
- package/lib/MultiParty/utils.d.ts +10 -0
- package/lib/MultiParty/utils.d.ts.map +1 -0
- package/lib/MultiParty/utils.js +17 -0
- package/lib/MultiParty/utils.js.map +1 -0
- package/lib/TechseeMediaStream.d.ts +7 -6
- package/lib/TechseeMediaStream.d.ts.map +1 -1
- package/lib/TechseeMediaStream.js +16 -18
- package/lib/TechseeMediaStream.js.map +1 -1
- package/lib/qos/raw-qos.d.ts +29 -0
- package/lib/qos/raw-qos.d.ts.map +1 -0
- package/lib/qos/raw-qos.js +84 -144
- package/lib/qos/raw-qos.js.map +1 -1
- package/lib/webrtc-ie-shim.d.ts +4 -0
- package/lib/webrtc-ie-shim.d.ts.map +1 -0
- package/lib/webrtc-ie-shim.js +1896 -2950
- package/lib/webrtc-ie-shim.js.map +1 -1
- package/package.json +79 -52
- package/lib/oldCode/constants.js +0 -20
- package/lib/oldCode/constants.js.map +0 -1
- package/lib/oldCode/event-emitter.js +0 -39
- package/lib/oldCode/event-emitter.js.map +0 -1
- package/lib/oldCode/index.js +0 -64
- package/lib/oldCode/index.js.map +0 -1
- package/lib/oldCode/opentok/session.js +0 -310
- package/lib/oldCode/opentok/session.js.map +0 -1
- package/lib/oldCode/opentok/stream.js +0 -310
- package/lib/oldCode/opentok/stream.js.map +0 -1
- package/lib/oldCode/publisher.js +0 -143
- package/lib/oldCode/publisher.js.map +0 -1
- package/lib/oldCode/service.js +0 -395
- package/lib/oldCode/service.js.map +0 -1
- package/lib/oldCode/session.js +0 -110
- package/lib/oldCode/session.js.map +0 -1
- package/lib/oldCode/stream.js +0 -195
- package/lib/oldCode/stream.js.map +0 -1
- package/lib/oldCode/subscriber.js +0 -90
- package/lib/oldCode/subscriber.js.map +0 -1
- package/lib/oldCode/tracer.d.ts +0 -35
- package/lib/oldCode/tracer.d.ts.map +0 -1
- package/lib/oldCode/tracer.js +0 -151
- package/lib/oldCode/tracer.js.map +0 -1
- package/lib/oldCode/utils/ImageFixer.d.ts +0 -1
- package/lib/oldCode/utils/ImageFixer.d.ts.map +0 -1
- package/lib/oldCode/utils/ImageFixer.js +0 -58
- package/lib/oldCode/utils/ImageFixer.js.map +0 -1
- package/lib/oldCode/webrtc/constants.js +0 -114
- package/lib/oldCode/webrtc/constants.js.map +0 -1
- package/lib/oldCode/webrtc/helper.js +0 -173
- package/lib/oldCode/webrtc/helper.js.map +0 -1
- package/lib/oldCode/webrtc/session-kms.js +0 -558
- package/lib/oldCode/webrtc/session-kms.js.map +0 -1
- package/lib/oldCode/webrtc/session-loopback.js +0 -336
- package/lib/oldCode/webrtc/session-loopback.js.map +0 -1
- package/lib/oldCode/webrtc/session-turn.js +0 -880
- package/lib/oldCode/webrtc/session-turn.js.map +0 -1
- package/lib/oldCode/webrtc/session-turn.v2.js +0 -583
- package/lib/oldCode/webrtc/session-turn.v2.js.map +0 -1
- package/lib/oldCode/webrtc/session.js +0 -52
- package/lib/oldCode/webrtc/session.js.map +0 -1
- package/lib/oldCode/webrtc/stream.js +0 -674
- package/lib/oldCode/webrtc/stream.js.map +0 -1
- package/lib/oldCode/webrtc/temasys/adapter-loader.js +0 -12
- package/lib/oldCode/webrtc/temasys/adapter-loader.js.map +0 -1
- package/lib/oldCode/webrtc/temasys/adapter.js +0 -5861
- package/lib/oldCode/webrtc/temasys/adapter.js.map +0 -1
- package/lib/oldCode/webrtc/webrtc-ie-shim.js +0 -3007
- package/lib/oldCode/webrtc/webrtc-ie-shim.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
# @techsee/techsee-media-service
|
|
2
2
|
|
|
3
3
|
**General Info**
|
|
4
|
-
This package is a starting point for creating Techsee Media SDK.
|
|
4
|
+
This package is a starting point for creating Techsee Media SDK.
|
|
5
5
|
It contains basic framework for creating applications that utilizes media abilities.
|
|
6
6
|
It can be video and/or audio, with or without streaming over WebRTC protocol.
|
|
7
|
-
The framework currently supports: Video+Voip over Techsee Video (Turn) + IE Plugin and OpenTOK + IE Plugin.
|
|
7
|
+
The framework currently supports: Video+Voip over Techsee Video (Turn) + IE Plugin and OpenTOK + IE Plugin.
|
|
8
8
|
|
|
9
9
|
You can see a very simple demo, which demonstrates how to create very basic MediaService implementation and use it for rendering video in react component.
|
|
10
|
-
Clone the repository, run `npm i`, then run `npm run demo`. The source code of the demo, can be found in ./demo folder.
|
|
10
|
+
Clone the repository, run `npm i`, then run `npm run demo`. The source code of the demo, can be found in ./demo folder.
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
14
14
|
Some basic framework principles are described below, which will help you to work with media framework.
|
|
15
15
|
|
|
16
16
|
**Framework actors**
|
|
17
|
-
`MediaStreamTrack` -
|
|
18
|
-
It can be video track (WebCam or ScreenShare), or audio track (Microphone stream).
|
|
19
|
-
|
|
17
|
+
`MediaStreamTrack` - WebRTC object, the most basic media unit.
|
|
18
|
+
It can be video track (WebCam or ScreenShare), or audio track (Microphone stream).
|
|
19
|
+
|
|
20
20
|
`MediaStream` - WebRTC object that just organizes multiple `MediaStreamTracks` into single group.
|
|
21
21
|
The same `MediaStreamTrack` can belong to multiple `MediaStreams`.
|
|
22
|
-
In Techsee Media Service implementation, `MediaStream` can not contain more than one `MediaStreamTrack` and it used only because HTML5 video element works with `MediaStream` object.
|
|
22
|
+
In Techsee Media Service implementation, `MediaStream` can not contain more than one `MediaStreamTrack` and it used only because HTML5 video element works with `MediaStream` object.
|
|
23
23
|
|
|
24
24
|
`TechseeMediaStream` - This is a logical wrapper for WebRTC `MediaStreamTrack` and manages some additional information regarding the specific `MediaStreamTrack`.
|
|
25
25
|
For example this object has the type of the `MediaStreamTrack` (USER_VIDEO, AGENT_AUDIO...etc), has indication if track is local or remote.
|
|
@@ -27,58 +27,57 @@ For example this object has the type of the `MediaStreamTrack` (USER_VIDEO, AGEN
|
|
|
27
27
|
`MediaSubscriber` - Techsee logical unit, that responsible to render `MediaStreams` into DOM.
|
|
28
28
|
In simple words this object creates video element in html, and renders `MediaStream` into it, when stream is ready.
|
|
29
29
|
`MediaSubscriber` is created for specific `MediaStream`, and whenever that stream created, the subscriber will start playing it.
|
|
30
|
-
The subscriber will notify it's consumers about the state changes through `onStateChanged` method.
|
|
30
|
+
The subscriber will notify it's consumers about the state changes through `onStateChanged` method.
|
|
31
31
|
|
|
32
32
|
`MediaSession` - Techsee logical unit, that used to stream video over WebRTC protocol. This object is responsible to handle all aspect of peers connectivity, including signaling, or third party service handling, like OpenTok.
|
|
33
33
|
When connection with peer established, this service registers `MediaStreamTracks` that received from peer and publishes local streams the connected peer.
|
|
34
34
|
Current implementation contains `MediaSessionBase` object, which have basic abstractions for all types of sessions. `SessionTurn` which handles the Techsee video sessions over TURN server.
|
|
35
35
|
`SessionOpentok` which handles the session connectivity over OpenTok third party service.
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
`RTCPeerConnection` - WebRTC object that represents connection with single peer, when SessionTurn is used for session. The same peer is used to send and/or receive media information.
|
|
38
38
|
|
|
39
|
-
`OTPeerConnection` - Design time only Typescript abstraction, which represents the connectivity with peer over OpenTok session.
|
|
39
|
+
`OTPeerConnection` - Design time only Typescript abstraction, which represents the connectivity with peer over OpenTok session.
|
|
40
40
|
|
|
41
41
|
`MediaPublisher` - Techsee logical unit which organizes local MediaStreamTracks into single MediaStream for publishing.
|
|
42
42
|
|
|
43
43
|
`MediaService` - Techsee logical unit. Represents the Facade of the framework and glues all of the above together.
|
|
44
44
|
Current implementation provides `MediaServiceBase` abstract object that contains all base logic and tools for displaying media locally or streaming it over WebRTC.
|
|
45
|
-
Each application should create its concrete `MediaService` and fill specific application logic gaps.
|
|
45
|
+
Each application should create its concrete `MediaService` and fill specific application logic gaps.
|
|
46
46
|
For example, currently exist `DashboardMediaService` in `techsee-app` and `MobileMediaService` in `techee-mobile`.
|
|
47
47
|
|
|
48
48
|
---
|
|
49
49
|
|
|
50
50
|
**Consuming media service - High Level Flow**
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
In order to be able to use media service, first you need to create and instance of it and initialize it.
|
|
53
|
-
Depending on application, the constructor parameters can be different, but MediaServiceBase need to get the following in it's constructor:
|
|
53
|
+
Depending on application, the constructor parameters can be different, but MediaServiceBase need to get the following in it's constructor:
|
|
54
54
|
|
|
55
55
|
`let mediaService = new SomeSpecificMediaService(environment, webRtcInfo);`
|
|
56
|
-
|
|
57
|
-
* **environment: IMediaEnvironment** - Service which will help understand in which environment the media service is currently running.
|
|
58
|
-
* **webRtcSupportInfo: ClientWebRtcInfo** - Information about WebRTC support on currently running device
|
|
59
56
|
|
|
57
|
+
- **environment: IMediaEnvironment** - Service which will help understand in which environment the media service is currently running.
|
|
58
|
+
- **webRtcSupportInfo: ClientWebRtcInfo** - Information about WebRTC support on currently running device
|
|
60
59
|
|
|
61
60
|
When instance of specific MediaService was created, it should be initialized with `mediaService.initMediaService(serviceOptions)` method.
|
|
62
61
|
See `MediaServiceOptions` for options details. The method returns promise that resolved when initialization is done.
|
|
63
62
|
Initialization process, detects what media support currently running device have.
|
|
64
63
|
It checks if video can be played (natively or using IE plugins), if device have mic and so on...
|
|
65
|
-
After initialization promise resolved, the device information get be accessed through `mediaService.deviceSupportInfo`.
|
|
64
|
+
After initialization promise resolved, the device information get be accessed through `mediaService.deviceSupportInfo`.
|
|
66
65
|
|
|
67
|
-
|
|
66
|
+
**_Note:_** Before promise returned by `mediaService.initMediaService(serviceOptions)` was not resolved, you not able to call `mediaService.initLocalMediaStreams(serviceOptions)`,
|
|
68
67
|
but you can create media subscribers if needed by calling `mediaService.createSubscriber(subscriberParams)`.
|
|
69
68
|
|
|
70
69
|
If audio stream is needed during the session, `mediaService.enableVoipDuringSession()` method should be called before initializing local streams.
|
|
71
|
-
After initialization was done and promise was resolved `mediaService.initLocalMediaStreams(serviceOptions)` can be called when video/audio streams should be created.
|
|
70
|
+
After initialization was done and promise was resolved `mediaService.initLocalMediaStreams(serviceOptions)` can be called when video/audio streams should be created.
|
|
72
71
|
This method will start the local MediaStream creation process, and Camera/ScreenShare approval dialog will popup if there permission currently exists.
|
|
73
72
|
`initLocalMediaStreams` method is called by controller which displays local media stream on mobile, and in MediaSession, when `peerConnection ` is created.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
`initLocalMediaStreams` synchronizes the calls and insures there only one instance of stream exists, and both sides receives the same one.
|
|
74
|
+
|
|
75
|
+
As mentioned before, `mediaService.createSubscriber(subscriberParams)` can be called even before initialization, so whenever you have the `div` container that should hold video element,
|
|
76
|
+
you can create the subscriber, by providing `KnownMediaStream` and `div` as container. Whenever the stream is ready, it will be played automatically by `MediaSubscriber`.
|
|
77
|
+
`MediaSubscriber` will create `video` element, add it to `div` container and will insure it plays.
|
|
78
|
+
`MediaSubscriber` has 'onStateChanged' method, which can be used for being notified on state changes of the subscriber.
|
|
79
|
+
It will notify when it starts or stops playing the video, or when it has been muted or unmuted. In event listener you can inspect properties of the subscriber to see in which state it currently exists.
|
|
80
|
+
In addition, `MediaSubscriber` has `onDispose` event handler, which will be called after `MediaSubscriber` was disposed and will never play video again, so references to it can be removed in order to avoid memory leaks.
|
|
82
81
|
|
|
83
82
|
**Connecting to WebRTC Media Session - High Level Flow**
|
|
84
83
|
|
|
@@ -86,4 +85,4 @@ After initialization promise was resolved, `mediaService.connectToSession(sessio
|
|
|
86
85
|
Connection to session can be done before media streams were initialized, if your use case requires it.
|
|
87
86
|
In case of of Techsee Live implementation, connection to session is done only when Terms and camera access approved by the user.
|
|
88
87
|
Depending on configuration passed in initialization method, `SessionTurn` or `SessionOpentok` will be created to manage the media session peers.
|
|
89
|
-
Whenever WebRTC peer will be connected, MediaSession instance will ask from `mediaService` for MediaStream that should be published to connected peer.
|
|
88
|
+
Whenever WebRTC peer will be connected, MediaSession instance will ask from `mediaService` for MediaStream that should be published to connected peer.
|
|
@@ -20,7 +20,7 @@ export declare class LocalStreamManager {
|
|
|
20
20
|
private environment;
|
|
21
21
|
private _groupedDevices;
|
|
22
22
|
constructor(environment: IMediaEnvironment);
|
|
23
|
-
|
|
23
|
+
get groupedDevices(): IGroupedDevices;
|
|
24
24
|
getUserMediaStream(constraints: LocalMediaConstraints): Promise<MediaRequestSuccessResult>;
|
|
25
25
|
getDesktopMediaStream(constraints: LocalVideoStreamConstraints): Promise<MediaRequestSuccessResult>;
|
|
26
26
|
destroyUserMediaStream(): Promise<void>;
|
|
@@ -37,3 +37,4 @@ export declare class LocalStreamManager {
|
|
|
37
37
|
private parseMediaErrorThenThrow;
|
|
38
38
|
}
|
|
39
39
|
export {};
|
|
40
|
+
//# sourceMappingURL=LocalStreamManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/LocalStreamManager.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,QAAQ,EAAC,MAAM,yBAAyB,CAAC;AAEjD,OAAO,EACH,iBAAiB,EACjB,qBAAqB,EACrB,2BAA2B,EAE3B,yBAAyB,EAE5B,MAAM,kBAAkB,CAAC;AAY1B,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,qBAAqB,EAAE,QAAQ,CAAC,yBAAyB,CAAC,CAAC;QAC3D,wBAAwB,EAAE,QAAQ,CAAC,yBAAyB,CAAC,CAAC;QAC9D,2BAA2B,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;QAC7D,0BAA0B,EAAE,OAAO,CAAC;KACvC;CACJ;AAeD,UAAU,eAAe;IACrB,KAAK,EAAE,QAAQ,CAAC;QAAE,IAAI,CAAC,EAAE,eAAe,CAAC;QAAC,KAAK,CAAC,EAAE,eAAe,CAAA;KAAE,CAAC,CAAC;IACrE,KAAK,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;IACjC,YAAY,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,eAAe,CAAgE;gBAE3E,WAAW,EAAE,iBAAiB;aAOtC,cAAc;IAIlB,kBAAkB,CAAC,WAAW,EAAE,qBAAqB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IA2C1F,qBAAqB,CAAC,WAAW,EAAE,2BAA2B,GAAG,OAAO,CAAC,yBAAyB,CAAC;IA4CnG,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAuBvC,yBAAyB,IAAI,OAAO,CAAC,IAAI,CAAC;IAqB1C,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAShC,OAAO,CAAC,0BAA0B;IAwDlC,OAAO,CAAC,6BAA6B;IAiBrC,OAAO,CAAC,mCAAmC;IAmD3C,iBAAiB,CAAC,cAAc,EAAE;QAAC,KAAK,EAAE,eAAe,EAAE,CAAC;QAAC,KAAK,EAAE,eAAe,EAAE,CAAA;KAAC;IAStF,OAAO,CAAC,oBAAoB;IAuE5B,OAAO,CAAC,wBAAwB;CAwCnC","file":"LocalStreamManager.d.ts","sourcesContent":["import assign from 'lodash/assign';\nimport get from 'lodash/get';\nimport last from 'lodash/last';\nimport first from 'lodash/first';\nimport cloneDeep from 'lodash/cloneDeep';\nimport {Promise} from 'bluebird';\n\nimport {Nullable} from '@techsee/techsee-common';\n\nimport {\n IMediaEnvironment,\n LocalMediaConstraints,\n LocalVideoStreamConstraints,\n MediaRequestFailResult,\n MediaRequestSuccessResult,\n VideoStreamResolution\n} from './MediaContracts';\n\nimport {\n CameraTypes,\n ConstraintType,\n DEFAULT_VIDEO_CONSTRAINT_TYPE,\n DEFAULT_VIDEO_RESOLUTION,\n LocalVideoSourceType,\n MediaRequestErrorCode\n} from './MediaConstants';\nimport {getMediaTracer} from './MediaUtils/MediaTracer';\n\ndeclare global {\n interface Window {\n latestUserMediaStream: Nullable<MediaRequestSuccessResult>;\n latestDesktopMediaStream: Nullable<MediaRequestSuccessResult>;\n latestLocalMediaConstraints: Nullable<LocalMediaConstraints>;\n mediaStreamAlreadyReplaced: boolean;\n }\n}\n\ndeclare const window: Window;\n\nwindow.latestUserMediaStream = null;\nlet userMediaPromise: Nullable<Promise<MediaRequestSuccessResult>> = null;\n\nwindow.latestDesktopMediaStream = null;\nlet desktopMediaPromise: Nullable<Promise<MediaRequestSuccessResult>> = null;\n\nwindow.mediaStreamAlreadyReplaced = false;\nwindow.latestLocalMediaConstraints = null;\n\nconst trace = getMediaTracer('LocalStreamManager');\n\ninterface IGroupedDevices {\n video: Nullable<{ back?: MediaDeviceInfo; front?: MediaDeviceInfo }>;\n audio: Nullable<MediaDeviceInfo>;\n camerasCount: number;\n}\n\nexport class LocalStreamManager {\n private environment: IMediaEnvironment;\n private _groupedDevices: IGroupedDevices = {video: null, audio: null, camerasCount: 0};\n\n constructor(environment: IMediaEnvironment) {\n this.environment = environment;\n\n this.parseMediaErrorThenThrow = this.parseMediaErrorThenThrow.bind(this);\n this.clearAllStreams = this.clearAllStreams.bind(this);\n }\n\n get groupedDevices() {\n return this._groupedDevices;\n }\n\n getUserMediaStream(constraints: LocalMediaConstraints): Promise<MediaRequestSuccessResult> {\n trace.info('getUserMediaStream', constraints);\n if (userMediaPromise) {\n return userMediaPromise;\n }\n\n if (window.latestUserMediaStream) {\n const videoTrack = window.latestUserMediaStream.mediaStream.getVideoTracks();\n\n if (videoTrack.length > 0 && videoTrack[0].readyState === 'live') {\n return Promise.resolve({...window.latestUserMediaStream, isNew: false});\n }\n\n this.destroyUserMediaStream();\n }\n\n userMediaPromise = new Promise((resolve, reject) => {\n const catchHandler = (err: any): void => {\n userMediaPromise = null;\n window.latestUserMediaStream = null;\n trace.error('getUserMedia error', err);\n reject(err);\n };\n\n try {\n this.getHighestResolutionStream(false, constraints)\n .then((streamResult: MediaRequestSuccessResult) => {\n userMediaPromise = null;\n window.latestUserMediaStream = streamResult;\n window.latestLocalMediaConstraints = cloneDeep(constraints);\n window.latestLocalMediaConstraints.audio = (streamResult.constraint && streamResult.constraint.audio) as boolean;\n\n resolve({...window.latestUserMediaStream, isNew: true});\n })\n .catch(catchHandler);\n } catch (err) {\n catchHandler(err);\n }\n });\n\n return userMediaPromise;\n }\n\n getDesktopMediaStream(constraints: LocalVideoStreamConstraints): Promise<MediaRequestSuccessResult> {\n if (desktopMediaPromise) {\n return desktopMediaPromise;\n }\n\n trace.info('getDesktopMediaStream', constraints);\n\n if (window.latestDesktopMediaStream) {\n const track = window.latestDesktopMediaStream.mediaStream.getVideoTracks();\n\n if (track.length > 0 && track[0].readyState === 'live') {\n //return Promise.resolve();\n return Promise.resolve({...window.latestDesktopMediaStream, isNew: false});\n }\n this.destroyDesktopMediaStream().catch((error: any) => {\n trace.error('Error destroying desktop media stream', error);\n });\n\n }\n\n desktopMediaPromise = new Promise((resolve, reject) => {\n const mediaCatchHandler = (err: any): void => {\n desktopMediaPromise = null;\n window.latestDesktopMediaStream = null;\n trace.error('getDisplayMedia error', err);\n reject(err);\n };\n\n try {\n this.getHighestResolutionStream(true, {video: constraints, audio: false})\n .then((streamResult: MediaRequestSuccessResult) => {\n desktopMediaPromise = null;\n window.latestDesktopMediaStream = streamResult;\n\n resolve({...window.latestDesktopMediaStream, isNew: true});\n }).catch(mediaCatchHandler);\n } catch (err) {\n mediaCatchHandler(err);\n }\n });\n\n return desktopMediaPromise;\n }\n\n destroyUserMediaStream(): Promise<void> {\n const streamResult = window.latestUserMediaStream;\n\n userMediaPromise = null;\n window.latestUserMediaStream = null;\n window.latestLocalMediaConstraints = null;\n window.mediaStreamAlreadyReplaced = false;\n\n if (streamResult && streamResult.mediaStream) {\n try {\n streamResult.mediaStream.getTracks().forEach((track: MediaStreamTrack) => {\n track.stop();\n });\n\n trace.info('destroyUserMediaStream - stop all tracks');\n } catch (e) {\n trace.info('destroyUserMediaStream - Failed to stop all tracks', e);\n }\n }\n\n return Promise.resolve();\n }\n\n destroyDesktopMediaStream(): Promise<void> {\n const streamResult = window.latestDesktopMediaStream;\n\n window.latestDesktopMediaStream = null;\n desktopMediaPromise = null;\n\n if (streamResult && streamResult.mediaStream) {\n try {\n streamResult.mediaStream.getTracks().forEach((track: MediaStreamTrack) => {\n track.stop();\n });\n\n trace.info('destroyDesktopMediaStream - stop all tracks');\n } catch (e) {\n trace.info('destroyDesktopMediaStream - Failed to stop all tracks', e);\n }\n }\n\n return Promise.resolve();\n }\n\n clearAllStreams(): Promise<void> {\n trace.info('LocalStreamManager Clearing all streams');\n\n return Promise.all([\n this.destroyDesktopMediaStream(),\n this.destroyUserMediaStream()\n ]).then(() => undefined);\n }\n\n private getHighestResolutionStream(isDesktopMedia: boolean, constraints?: LocalMediaConstraints): Promise<MediaRequestSuccessResult> {\n const constraintsCandidates = this.getParsedConstraints(isDesktopMedia, constraints);\n\n trace.info('getHighestResolutionStream - constraintsCandidates:', constraintsCandidates);\n\n if (constraintsCandidates.length === 0) {\n return Promise.reject(new Error('No constraints to retrieve the stream'));\n }\n\n return new Promise((resolve, reject) => {\n let lastSuccessfulResult: Nullable<MediaRequestSuccessResult> = null;\n let lastFailedResult: Nullable<MediaRequestFailResult> = null;\n let isStreamRequestFulfilled = false;\n\n (Promise as any).reduce(constraintsCandidates, (total: any, candidate: MediaStreamConstraints) => {\n if (isStreamRequestFulfilled) {\n return;\n }\n\n const constraintType = get(constraints, 'video.videoResolution.constraintType') || get(constraints, 'video.videoResolution[0].constraintType');\n\n return this.getStreamPromiseByParsedConstraints(candidate, isDesktopMedia)\n .then((stream: MediaStream) => {\n lastSuccessfulResult = {\n mediaStream: stream,\n constraint: candidate,\n constraintType,\n isNew: true\n };\n trace.info('getHighestResolutionStream Success', lastSuccessfulResult);\n isStreamRequestFulfilled = true;\n resolve(lastSuccessfulResult);\n })\n .catch((failResult: MediaRequestFailResult) => {\n lastFailedResult = failResult;\n\n if (lastFailedResult.errorCode === MediaRequestErrorCode.PermissionDenied) {\n isStreamRequestFulfilled = true;\n reject(lastFailedResult);\n }\n });\n }, 0)\n .then(() => {\n if (!isStreamRequestFulfilled) {\n if (!lastFailedResult) {\n lastFailedResult = {\n errorCode: MediaRequestErrorCode.GeneralError,\n message: 'Suitable stream cannot be created'\n };\n }\n reject(lastFailedResult);\n }\n });\n });\n }\n\n private getUserMediaStreamMediaDevice(constraints: MediaStreamConstraints, isDesktopMedia: boolean) {\n let streamPromise = null;\n\n if (!isDesktopMedia) {\n streamPromise = navigator.mediaDevices.getUserMedia(constraints);\n } else {\n //@ts-ignore\n streamPromise = navigator.mediaDevices.getDisplayMedia\n //@ts-ignore\n ? navigator.mediaDevices.getDisplayMedia(constraints)\n : navigator.getDisplayMedia(constraints);\n }\n\n return streamPromise;\n }\n\n //@ts-ignore\n private getStreamPromiseByParsedConstraints(constraints: MediaStreamConstraints, isDesktopMedia: boolean): Promise<MediaStream> {\n trace.info('getStreamPromiseByParsedConstraints', constraints);\n\n try {\n return this.getUserMediaStreamMediaDevice(constraints, isDesktopMedia).catch((err: any) => {\n let streamPromise = null;\n\n trace.info('getStreamPromiseByParsedConstraints - get user stream error', err.name);\n\n // Android (Galaxy esp.) have a bug that when using facingMode it might cause NotReadableError. So\n // we should try again but without facingMode. The exception to the rule is when we don't have specific\n // device to use (like in IOS13 bug, as can be seen in MediaServiceBase.ts), in that case, we might end\n // up using the front camera, which is a privacy concern and the preference is to fallback from video\n if (err && (err.name === 'NotReadableError') && get(constraints, 'video.facingMode') &&\n get(constraints, 'video.deviceId')) {\n\n const newConstraints = constraints;\n\n trace.info(`getStreamPromiseByParsedConstraints - NotReadableError - Failed to get video user media stream with facingMode=${get(constraints, 'video.facingMode')}`, err.name);\n\n // @ts-ignore\n delete newConstraints.video.facingMode;\n ((newConstraints.video as MediaTrackConstraints).deviceId as ConstrainDOMStringParameters) = {\n exact: (constraints.video as MediaTrackConstraints).deviceId\n } as any as ConstrainDOMStringParameters;\n\n streamPromise = this.getStreamPromiseByParsedConstraints(newConstraints, isDesktopMedia);\n } else if (err && err.name && constraints.audio && !constraints.video) {\n trace.info('getStreamPromiseByParsedConstraints - audioStreamFailed - Failed to get audio user media stream', err.name);\n\n return this.parseMediaErrorThenThrow({name: 'audioStreamFailed'});\n } else if (err && err.name && constraints.audio) {\n const newConstraints = constraints;\n\n trace.info('getStreamPromiseByParsedConstraints - Failed to get video and audio user media stream, try to get video media stream only', err.name);\n\n newConstraints.audio = false;\n streamPromise = this.getStreamPromiseByParsedConstraints(newConstraints, isDesktopMedia);\n } else if (err && !streamPromise) {\n trace.info('getStreamPromiseByParsedConstraints - Failed to get video user media stream', err && err.name);\n\n streamPromise = Promise.reject(err);\n }\n\n return streamPromise && streamPromise.catch(this.parseMediaErrorThenThrow);\n });\n } catch (e) {\n this.parseMediaErrorThenThrow(e);\n }\n }\n\n setGroupedDevices(groupedDevices: {video: MediaDeviceInfo[]; audio: MediaDeviceInfo[]}) {\n trace.info('setGroupedDevices', groupedDevices);\n this._groupedDevices = {video: groupedDevices.video\n ? {[CameraTypes.BACK]: last(groupedDevices.video), [CameraTypes.FRONT]: first(groupedDevices.video)}\n : null,\n audio: last(groupedDevices.audio) || null,\n camerasCount: groupedDevices.video.length};\n }\n\n private getParsedConstraints(isDesktopMedia: boolean, streamConstraints?: LocalMediaConstraints): MediaStreamConstraints[] {\n const constraintCandidates: MediaStreamConstraints[] = [];\n\n //TODO - Alex: need to understand which constraints not compatible with screen share\n if (isDesktopMedia) {\n return [{video: true}];\n }\n\n if (!streamConstraints) {\n return constraintCandidates;\n }\n\n const baseConstraints: MediaStreamConstraints = {};\n\n baseConstraints.audio = typeof streamConstraints.audio === 'boolean' ? streamConstraints.audio : undefined;\n\n if (!streamConstraints.video) {\n return [baseConstraints];\n }\n\n const cameraType = (streamConstraints.video !== 'boolean') &&\n (streamConstraints.video as LocalVideoStreamConstraints).videoSourceType;\n\n baseConstraints.video = {\n facingMode: cameraType && cameraType === LocalVideoSourceType.CAMERA_FRONT\n ? 'user'\n : 'environment',\n frameRate: {ideal: 15, max: 30}\n };\n\n const deviceId = get(this._groupedDevices, `video.${cameraType === LocalVideoSourceType.CAMERA_FRONT\n ? CameraTypes.FRONT\n : CameraTypes.BACK}.deviceId`);\n\n if (deviceId) {\n baseConstraints.video.deviceId = deviceId;\n\n if (this._groupedDevices.camerasCount > 1) {\n baseConstraints.video.facingMode = {exact: baseConstraints.video.facingMode} as any as ConstrainDOMStringParameters;\n }\n }\n\n const assignConstraint = (videoResolution: VideoStreamResolution): void => {\n const [width, height] = videoResolution.resolution.split('x');\n const constraintCandidate = assign({}, baseConstraints);\n\n constraintCandidate.video = assign({}, baseConstraints.video, {\n width: _constraintByType(width, videoResolution.constraintType),\n height: _constraintByType(height, videoResolution.constraintType)\n });\n constraintCandidates.push(constraintCandidate);\n };\n\n if ((baseConstraints.video && typeof streamConstraints.video === 'boolean') ||\n !((streamConstraints.video as LocalVideoStreamConstraints).videoResolution instanceof Array)) {\n\n const defaultResolution: VideoStreamResolution = {\n resolution: DEFAULT_VIDEO_RESOLUTION,\n constraintType: DEFAULT_VIDEO_CONSTRAINT_TYPE\n };\n\n assignConstraint(defaultResolution);\n\n return constraintCandidates;\n }\n\n (streamConstraints.video as any).videoResolution.forEach(assignConstraint);\n\n return constraintCandidates;\n }\n\n private parseMediaErrorThenThrow(error: any): MediaRequestFailResult {\n if (error && error.errorCode) {\n throw error;\n }\n\n trace.error('Get media stream error.', error);\n const errorName = error && error.name ? error.name : '';\n\n const permissionErrorNames = [\n 'NotAllowedError',\n 'PermissionDismissedError',\n 'PermissionDeniedError'\n\n ];\n\n // const generalError = [\n // 'NotFoundError',\n // 'DevicesNotFoundError',\n // 'NotReadableError',\n // 'TrackStartError'\n // ];\n\n const constraintsErrors = [\n 'OverconstrainedError',\n 'ConstraintNotSatisfiedError'\n\n ];\n\n const isErrorOfType = (errorsArr: string[]) => errorsArr.filter((err: string) => err === errorName).length > 0;\n\n if (isErrorOfType(permissionErrorNames)) {\n throw {errorCode: MediaRequestErrorCode.PermissionDenied, message: errorName};\n }\n\n if (isErrorOfType(constraintsErrors)) {\n throw {errorCode: MediaRequestErrorCode.Overconstrained, message: errorName};\n }\n\n throw {errorCode: MediaRequestErrorCode.GeneralError, message: errorName};\n }\n}\n\nfunction _constraintByType(value: any, type: ConstraintType): any {\n switch (type) {\n case ConstraintType.MIN:\n return {min: value};\n default:\n return {ideal: value};\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"LocalStreamManager.d.ts","sourceRoot":"","sources":["../src/LocalStreamManager.ts"],"names":[],"mappings":"AASA,OAAO,EAAC,QAAQ,EAAC,MAAM,yBAAyB,CAAC;AAEjD,OAAO,EACH,iBAAiB,EACjB,qBAAqB,EACrB,2BAA2B,EAE3B,yBAAyB,EAE5B,MAAM,kBAAkB,CAAC;AAY1B,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,qBAAqB,EAAE,QAAQ,CAAC,yBAAyB,CAAC,CAAC;QAC3D,wBAAwB,EAAE,QAAQ,CAAC,yBAAyB,CAAC,CAAC;QAC9D,2BAA2B,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;QAC7D,0BAA0B,EAAE,OAAO,CAAC;KACvC;CACJ;AAeD,UAAU,eAAe;IACrB,KAAK,EAAE,QAAQ,CAAC;QAAC,IAAI,CAAC,EAAE,eAAe,CAAC;QAAC,KAAK,CAAC,EAAE,eAAe,CAAA;KAAC,CAAC,CAAC;IACnE,KAAK,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;IACjC,YAAY,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,WAAW,CAAoB;IAEvC,OAAO,CAAC,eAAe,CAAgE;gBAE3E,WAAW,EAAE,iBAAiB;IAO1C,IAAI,cAAc,oBAEjB;IAED,kBAAkB,CAAC,WAAW,EAAE,qBAAqB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IA4C1F,qBAAqB,CAAC,WAAW,EAAE,2BAA2B,GAAG,OAAO,CAAC,yBAAyB,CAAC;IA4CnG,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAuBvC,yBAAyB,IAAI,OAAO,CAAC,IAAI,CAAC;IAqB1C,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAMhC,OAAO,CAAC,0BAA0B;IAkElC,OAAO,CAAC,6BAA6B;IAoBrC,OAAO,CAAC,mCAAmC;IA0E3C,iBAAiB,CAAC,cAAc,EAAE;QAAC,KAAK,EAAE,eAAe,EAAE,CAAC;QAAC,KAAK,EAAE,eAAe,EAAE,CAAA;KAAC;IAWtF,OAAO,CAAC,oBAAoB;IAiF5B,OAAO,CAAC,wBAAwB;CA+BnC"}
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
__assign = Object.assign || function (t) {
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
5
4
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
5
|
s = arguments[i];
|
|
7
|
-
for (var p in s)
|
|
8
|
-
|
|
9
|
-
}
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
10
8
|
}
|
|
11
9
|
return t;
|
|
12
10
|
};
|
|
13
11
|
return __assign.apply(this, arguments);
|
|
14
12
|
};
|
|
15
|
-
var __importDefault =
|
|
16
|
-
return mod && mod.__esModule ? mod : { "default": mod };
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
15
|
};
|
|
18
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.LocalStreamManager = void 0;
|
|
19
18
|
var assign_1 = __importDefault(require("lodash/assign"));
|
|
20
19
|
var get_1 = __importDefault(require("lodash/get"));
|
|
21
20
|
var last_1 = __importDefault(require("lodash/last"));
|
|
@@ -30,8 +29,8 @@ window.latestDesktopMediaStream = null;
|
|
|
30
29
|
var desktopMediaPromise = null;
|
|
31
30
|
window.mediaStreamAlreadyReplaced = false;
|
|
32
31
|
window.latestLocalMediaConstraints = null;
|
|
33
|
-
var trace = MediaTracer_1.getMediaTracer('LocalStreamManager');
|
|
34
|
-
var LocalStreamManager =
|
|
32
|
+
var trace = (0, MediaTracer_1.getMediaTracer)('LocalStreamManager');
|
|
33
|
+
var LocalStreamManager = (function () {
|
|
35
34
|
function LocalStreamManager(environment) {
|
|
36
35
|
this._groupedDevices = { video: null, audio: null, camerasCount: 0 };
|
|
37
36
|
this.environment = environment;
|
|
@@ -39,10 +38,10 @@ var LocalStreamManager = /** @class */function () {
|
|
|
39
38
|
this.clearAllStreams = this.clearAllStreams.bind(this);
|
|
40
39
|
}
|
|
41
40
|
Object.defineProperty(LocalStreamManager.prototype, "groupedDevices", {
|
|
42
|
-
get: function
|
|
41
|
+
get: function () {
|
|
43
42
|
return this._groupedDevices;
|
|
44
43
|
},
|
|
45
|
-
enumerable:
|
|
44
|
+
enumerable: false,
|
|
46
45
|
configurable: true
|
|
47
46
|
});
|
|
48
47
|
LocalStreamManager.prototype.getUserMediaStream = function (constraints) {
|
|
@@ -54,26 +53,30 @@ var LocalStreamManager = /** @class */function () {
|
|
|
54
53
|
if (window.latestUserMediaStream) {
|
|
55
54
|
var videoTrack = window.latestUserMediaStream.mediaStream.getVideoTracks();
|
|
56
55
|
if (videoTrack.length > 0 && videoTrack[0].readyState === 'live') {
|
|
57
|
-
return bluebird_1.Promise.resolve(__assign({}, window.latestUserMediaStream, { isNew: false }));
|
|
56
|
+
return bluebird_1.Promise.resolve(__assign(__assign({}, window.latestUserMediaStream), { isNew: false }));
|
|
58
57
|
}
|
|
59
58
|
this.destroyUserMediaStream();
|
|
60
59
|
}
|
|
61
60
|
userMediaPromise = new bluebird_1.Promise(function (resolve, reject) {
|
|
62
|
-
var catchHandler = function
|
|
61
|
+
var catchHandler = function (err) {
|
|
63
62
|
userMediaPromise = null;
|
|
64
63
|
window.latestUserMediaStream = null;
|
|
65
64
|
trace.error('getUserMedia error', err);
|
|
66
65
|
reject(err);
|
|
67
66
|
};
|
|
68
67
|
try {
|
|
69
|
-
_this.getHighestResolutionStream(false, constraints)
|
|
68
|
+
_this.getHighestResolutionStream(false, constraints)
|
|
69
|
+
.then(function (streamResult) {
|
|
70
70
|
userMediaPromise = null;
|
|
71
71
|
window.latestUserMediaStream = streamResult;
|
|
72
|
-
window.latestLocalMediaConstraints = cloneDeep_1.default(constraints);
|
|
73
|
-
window.latestLocalMediaConstraints.audio = streamResult.constraint &&
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
window.latestLocalMediaConstraints = (0, cloneDeep_1.default)(constraints);
|
|
73
|
+
window.latestLocalMediaConstraints.audio = (streamResult.constraint &&
|
|
74
|
+
streamResult.constraint.audio);
|
|
75
|
+
resolve(__assign(__assign({}, window.latestUserMediaStream), { isNew: true }));
|
|
76
|
+
})
|
|
77
|
+
.catch(catchHandler);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
77
80
|
catchHandler(err);
|
|
78
81
|
}
|
|
79
82
|
});
|
|
@@ -88,27 +91,29 @@ var LocalStreamManager = /** @class */function () {
|
|
|
88
91
|
if (window.latestDesktopMediaStream) {
|
|
89
92
|
var track = window.latestDesktopMediaStream.mediaStream.getVideoTracks();
|
|
90
93
|
if (track.length > 0 && track[0].readyState === 'live') {
|
|
91
|
-
|
|
92
|
-
return bluebird_1.Promise.resolve(__assign({}, window.latestDesktopMediaStream, { isNew: false }));
|
|
94
|
+
return bluebird_1.Promise.resolve(__assign(__assign({}, window.latestDesktopMediaStream), { isNew: false }));
|
|
93
95
|
}
|
|
94
96
|
this.destroyDesktopMediaStream().catch(function (error) {
|
|
95
97
|
trace.error('Error destroying desktop media stream', error);
|
|
96
98
|
});
|
|
97
99
|
}
|
|
98
100
|
desktopMediaPromise = new bluebird_1.Promise(function (resolve, reject) {
|
|
99
|
-
var mediaCatchHandler = function
|
|
101
|
+
var mediaCatchHandler = function (err) {
|
|
100
102
|
desktopMediaPromise = null;
|
|
101
103
|
window.latestDesktopMediaStream = null;
|
|
102
104
|
trace.error('getDisplayMedia error', err);
|
|
103
105
|
reject(err);
|
|
104
106
|
};
|
|
105
107
|
try {
|
|
106
|
-
_this.getHighestResolutionStream(true, { video: constraints, audio: false })
|
|
108
|
+
_this.getHighestResolutionStream(true, { video: constraints, audio: false })
|
|
109
|
+
.then(function (streamResult) {
|
|
107
110
|
desktopMediaPromise = null;
|
|
108
111
|
window.latestDesktopMediaStream = streamResult;
|
|
109
|
-
resolve(__assign({}, window.latestDesktopMediaStream, { isNew: true }));
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
+
resolve(__assign(__assign({}, window.latestDesktopMediaStream), { isNew: true }));
|
|
113
|
+
})
|
|
114
|
+
.catch(mediaCatchHandler);
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
112
117
|
mediaCatchHandler(err);
|
|
113
118
|
}
|
|
114
119
|
});
|
|
@@ -126,7 +131,8 @@ var LocalStreamManager = /** @class */function () {
|
|
|
126
131
|
track.stop();
|
|
127
132
|
});
|
|
128
133
|
trace.info('destroyUserMediaStream - stop all tracks');
|
|
129
|
-
}
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
130
136
|
trace.info('destroyUserMediaStream - Failed to stop all tracks', e);
|
|
131
137
|
}
|
|
132
138
|
}
|
|
@@ -142,7 +148,8 @@ var LocalStreamManager = /** @class */function () {
|
|
|
142
148
|
track.stop();
|
|
143
149
|
});
|
|
144
150
|
trace.info('destroyDesktopMediaStream - stop all tracks');
|
|
145
|
-
}
|
|
151
|
+
}
|
|
152
|
+
catch (e) {
|
|
146
153
|
trace.info('destroyDesktopMediaStream - Failed to stop all tracks', e);
|
|
147
154
|
}
|
|
148
155
|
}
|
|
@@ -150,9 +157,7 @@ var LocalStreamManager = /** @class */function () {
|
|
|
150
157
|
};
|
|
151
158
|
LocalStreamManager.prototype.clearAllStreams = function () {
|
|
152
159
|
trace.info('LocalStreamManager Clearing all streams');
|
|
153
|
-
return bluebird_1.Promise.all([this.destroyDesktopMediaStream(), this.destroyUserMediaStream()]).then(function () {
|
|
154
|
-
return undefined;
|
|
155
|
-
});
|
|
160
|
+
return bluebird_1.Promise.all([this.destroyDesktopMediaStream(), this.destroyUserMediaStream()]).then(function () { return undefined; });
|
|
156
161
|
};
|
|
157
162
|
LocalStreamManager.prototype.getHighestResolutionStream = function (isDesktopMedia, constraints) {
|
|
158
163
|
var _this = this;
|
|
@@ -165,12 +170,15 @@ var LocalStreamManager = /** @class */function () {
|
|
|
165
170
|
var lastSuccessfulResult = null;
|
|
166
171
|
var lastFailedResult = null;
|
|
167
172
|
var isStreamRequestFulfilled = false;
|
|
168
|
-
bluebird_1.Promise
|
|
173
|
+
bluebird_1.Promise
|
|
174
|
+
.reduce(constraintsCandidates, function (total, candidate) {
|
|
169
175
|
if (isStreamRequestFulfilled) {
|
|
170
176
|
return;
|
|
171
177
|
}
|
|
172
|
-
var constraintType =
|
|
173
|
-
|
|
178
|
+
var constraintType = (0, get_1.default)(constraints, 'video.videoResolution.constraintType') ||
|
|
179
|
+
(0, get_1.default)(constraints, 'video.videoResolution[0].constraintType');
|
|
180
|
+
return _this.getStreamPromiseByParsedConstraints(candidate, isDesktopMedia)
|
|
181
|
+
.then(function (stream) {
|
|
174
182
|
lastSuccessfulResult = {
|
|
175
183
|
mediaStream: stream,
|
|
176
184
|
constraint: candidate,
|
|
@@ -180,14 +188,16 @@ var LocalStreamManager = /** @class */function () {
|
|
|
180
188
|
trace.info('getHighestResolutionStream Success', lastSuccessfulResult);
|
|
181
189
|
isStreamRequestFulfilled = true;
|
|
182
190
|
resolve(lastSuccessfulResult);
|
|
183
|
-
})
|
|
191
|
+
})
|
|
192
|
+
.catch(function (failResult) {
|
|
184
193
|
lastFailedResult = failResult;
|
|
185
194
|
if (lastFailedResult.errorCode === MediaConstants_1.MediaRequestErrorCode.PermissionDenied) {
|
|
186
195
|
isStreamRequestFulfilled = true;
|
|
187
196
|
reject(lastFailedResult);
|
|
188
197
|
}
|
|
189
198
|
});
|
|
190
|
-
}, 0)
|
|
199
|
+
}, 0)
|
|
200
|
+
.then(function () {
|
|
191
201
|
if (!isStreamRequestFulfilled) {
|
|
192
202
|
if (!lastFailedResult) {
|
|
193
203
|
lastFailedResult = {
|
|
@@ -204,15 +214,16 @@ var LocalStreamManager = /** @class */function () {
|
|
|
204
214
|
var streamPromise = null;
|
|
205
215
|
if (!isDesktopMedia) {
|
|
206
216
|
streamPromise = navigator.mediaDevices.getUserMedia(constraints);
|
|
207
|
-
}
|
|
208
|
-
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
209
219
|
streamPromise = navigator.mediaDevices.getDisplayMedia
|
|
210
|
-
|
|
211
|
-
|
|
220
|
+
?
|
|
221
|
+
navigator.mediaDevices.getDisplayMedia(constraints)
|
|
222
|
+
:
|
|
223
|
+
navigator.getDisplayMedia(constraints);
|
|
212
224
|
}
|
|
213
225
|
return streamPromise;
|
|
214
226
|
};
|
|
215
|
-
//@ts-ignore
|
|
216
227
|
LocalStreamManager.prototype.getStreamPromiseByParsedConstraints = function (constraints, isDesktopMedia) {
|
|
217
228
|
var _this = this;
|
|
218
229
|
trace.info('getStreamPromiseByParsedConstraints', constraints);
|
|
@@ -220,47 +231,51 @@ var LocalStreamManager = /** @class */function () {
|
|
|
220
231
|
return this.getUserMediaStreamMediaDevice(constraints, isDesktopMedia).catch(function (err) {
|
|
221
232
|
var streamPromise = null;
|
|
222
233
|
trace.info('getStreamPromiseByParsedConstraints - get user stream error', err.name);
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
if (err && err.name === 'NotReadableError' && get_1.default(constraints, 'video.facingMode') && get_1.default(constraints, 'video.deviceId')) {
|
|
234
|
+
if (err &&
|
|
235
|
+
err.name === 'NotReadableError' &&
|
|
236
|
+
(0, get_1.default)(constraints, 'video.facingMode') &&
|
|
237
|
+
(0, get_1.default)(constraints, 'video.deviceId')) {
|
|
228
238
|
var newConstraints = constraints;
|
|
229
|
-
trace.info("getStreamPromiseByParsedConstraints - NotReadableError - Failed to get video user media stream with facingMode="
|
|
230
|
-
// @ts-ignore
|
|
239
|
+
trace.info("getStreamPromiseByParsedConstraints - NotReadableError - Failed to get video user media stream with facingMode=".concat((0, get_1.default)(constraints, 'video.facingMode')), err.name);
|
|
231
240
|
delete newConstraints.video.facingMode;
|
|
232
241
|
newConstraints.video.deviceId = {
|
|
233
242
|
exact: constraints.video.deviceId
|
|
234
243
|
};
|
|
235
244
|
streamPromise = _this.getStreamPromiseByParsedConstraints(newConstraints, isDesktopMedia);
|
|
236
|
-
}
|
|
245
|
+
}
|
|
246
|
+
else if (err && err.name && constraints.audio && !constraints.video) {
|
|
237
247
|
trace.info('getStreamPromiseByParsedConstraints - audioStreamFailed - Failed to get audio user media stream', err.name);
|
|
238
248
|
return _this.parseMediaErrorThenThrow({ name: 'audioStreamFailed' });
|
|
239
|
-
}
|
|
249
|
+
}
|
|
250
|
+
else if (err && err.name && constraints.audio) {
|
|
240
251
|
var newConstraints = constraints;
|
|
241
252
|
trace.info('getStreamPromiseByParsedConstraints - Failed to get video and audio user media stream, try to get video media stream only', err.name);
|
|
242
253
|
newConstraints.audio = false;
|
|
243
254
|
streamPromise = _this.getStreamPromiseByParsedConstraints(newConstraints, isDesktopMedia);
|
|
244
|
-
}
|
|
255
|
+
}
|
|
256
|
+
else if (err && !streamPromise) {
|
|
245
257
|
trace.info('getStreamPromiseByParsedConstraints - Failed to get video user media stream', err && err.name);
|
|
246
258
|
streamPromise = bluebird_1.Promise.reject(err);
|
|
247
259
|
}
|
|
248
260
|
return streamPromise && streamPromise.catch(_this.parseMediaErrorThenThrow);
|
|
249
261
|
});
|
|
250
|
-
}
|
|
251
|
-
|
|
262
|
+
}
|
|
263
|
+
catch (e) {
|
|
264
|
+
return this.parseMediaErrorThenThrow(e);
|
|
252
265
|
}
|
|
253
266
|
};
|
|
254
267
|
LocalStreamManager.prototype.setGroupedDevices = function (groupedDevices) {
|
|
255
268
|
var _a;
|
|
256
269
|
trace.info('setGroupedDevices', groupedDevices);
|
|
257
|
-
this._groupedDevices = {
|
|
258
|
-
|
|
259
|
-
|
|
270
|
+
this._groupedDevices = {
|
|
271
|
+
video: groupedDevices.video
|
|
272
|
+
? (_a = {}, _a[MediaConstants_1.CameraTypes.BACK] = (0, last_1.default)(groupedDevices.video), _a[MediaConstants_1.CameraTypes.FRONT] = (0, first_1.default)(groupedDevices.video), _a) : null,
|
|
273
|
+
audio: (0, last_1.default)(groupedDevices.audio) || null,
|
|
274
|
+
camerasCount: groupedDevices.video.length
|
|
275
|
+
};
|
|
260
276
|
};
|
|
261
277
|
LocalStreamManager.prototype.getParsedConstraints = function (isDesktopMedia, streamConstraints) {
|
|
262
278
|
var constraintCandidates = [];
|
|
263
|
-
//TODO - Alex: need to understand which constraints not compatible with screen share
|
|
264
279
|
if (isDesktopMedia) {
|
|
265
280
|
return [{ video: true }];
|
|
266
281
|
}
|
|
@@ -269,33 +284,38 @@ var LocalStreamManager = /** @class */function () {
|
|
|
269
284
|
}
|
|
270
285
|
var baseConstraints = {};
|
|
271
286
|
baseConstraints.audio = typeof streamConstraints.audio === 'boolean' ? streamConstraints.audio : undefined;
|
|
287
|
+
if (baseConstraints.audio === undefined) {
|
|
288
|
+
delete baseConstraints.audio;
|
|
289
|
+
}
|
|
272
290
|
if (!streamConstraints.video) {
|
|
273
291
|
return [baseConstraints];
|
|
274
292
|
}
|
|
275
|
-
var cameraType = streamConstraints.video !== 'boolean' &&
|
|
293
|
+
var cameraType = typeof streamConstraints.video !== 'boolean' &&
|
|
294
|
+
streamConstraints.video.videoSourceType;
|
|
276
295
|
baseConstraints.video = {
|
|
277
296
|
facingMode: cameraType && cameraType === MediaConstants_1.LocalVideoSourceType.CAMERA_FRONT ? 'user' : 'environment',
|
|
278
297
|
frameRate: { ideal: 15, max: 30 }
|
|
279
298
|
};
|
|
280
|
-
var deviceId = get_1.default(this._groupedDevices, "video."
|
|
299
|
+
var deviceId = (0, get_1.default)(this._groupedDevices, "video.".concat(cameraType === MediaConstants_1.LocalVideoSourceType.CAMERA_FRONT ? MediaConstants_1.CameraTypes.FRONT : MediaConstants_1.CameraTypes.BACK, ".deviceId"));
|
|
281
300
|
if (deviceId) {
|
|
282
301
|
baseConstraints.video.deviceId = deviceId;
|
|
283
302
|
if (this._groupedDevices.camerasCount > 1) {
|
|
284
|
-
baseConstraints.video.facingMode = {
|
|
303
|
+
baseConstraints.video.facingMode = {
|
|
304
|
+
exact: baseConstraints.video.facingMode
|
|
305
|
+
};
|
|
285
306
|
}
|
|
286
307
|
}
|
|
287
|
-
var assignConstraint = function
|
|
288
|
-
var _a = videoResolution.resolution.split('x'),
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
var constraintCandidate = assign_1.default({}, baseConstraints);
|
|
292
|
-
constraintCandidate.video = assign_1.default({}, baseConstraints.video, {
|
|
308
|
+
var assignConstraint = function (videoResolution) {
|
|
309
|
+
var _a = videoResolution.resolution.split('x'), width = _a[0], height = _a[1];
|
|
310
|
+
var constraintCandidate = (0, assign_1.default)({}, baseConstraints);
|
|
311
|
+
constraintCandidate.video = (0, assign_1.default)({}, baseConstraints.video, {
|
|
293
312
|
width: _constraintByType(width, videoResolution.constraintType),
|
|
294
313
|
height: _constraintByType(height, videoResolution.constraintType)
|
|
295
314
|
});
|
|
296
315
|
constraintCandidates.push(constraintCandidate);
|
|
297
316
|
};
|
|
298
|
-
if (baseConstraints.video && typeof streamConstraints.video === 'boolean' ||
|
|
317
|
+
if ((baseConstraints.video && typeof streamConstraints.video === 'boolean') ||
|
|
318
|
+
!(streamConstraints.video.videoResolution instanceof Array)) {
|
|
299
319
|
var defaultResolution = {
|
|
300
320
|
resolution: MediaConstants_1.DEFAULT_VIDEO_RESOLUTION,
|
|
301
321
|
constraintType: MediaConstants_1.DEFAULT_VIDEO_CONSTRAINT_TYPE
|
|
@@ -313,18 +333,8 @@ var LocalStreamManager = /** @class */function () {
|
|
|
313
333
|
trace.error('Get media stream error.', error);
|
|
314
334
|
var errorName = error && error.name ? error.name : '';
|
|
315
335
|
var permissionErrorNames = ['NotAllowedError', 'PermissionDismissedError', 'PermissionDeniedError'];
|
|
316
|
-
// const generalError = [
|
|
317
|
-
// 'NotFoundError',
|
|
318
|
-
// 'DevicesNotFoundError',
|
|
319
|
-
// 'NotReadableError',
|
|
320
|
-
// 'TrackStartError'
|
|
321
|
-
// ];
|
|
322
336
|
var constraintsErrors = ['OverconstrainedError', 'ConstraintNotSatisfiedError'];
|
|
323
|
-
var isErrorOfType = function
|
|
324
|
-
return errorsArr.filter(function (err) {
|
|
325
|
-
return err === errorName;
|
|
326
|
-
}).length > 0;
|
|
327
|
-
};
|
|
337
|
+
var isErrorOfType = function (errorsArr) { return errorsArr.filter(function (err) { return err === errorName; }).length > 0; };
|
|
328
338
|
if (isErrorOfType(permissionErrorNames)) {
|
|
329
339
|
throw { errorCode: MediaConstants_1.MediaRequestErrorCode.PermissionDenied, message: errorName };
|
|
330
340
|
}
|
|
@@ -334,7 +344,7 @@ var LocalStreamManager = /** @class */function () {
|
|
|
334
344
|
throw { errorCode: MediaConstants_1.MediaRequestErrorCode.GeneralError, message: errorName };
|
|
335
345
|
};
|
|
336
346
|
return LocalStreamManager;
|
|
337
|
-
}();
|
|
347
|
+
}());
|
|
338
348
|
exports.LocalStreamManager = LocalStreamManager;
|
|
339
349
|
function _constraintByType(value, type) {
|
|
340
350
|
switch (type) {
|
|
@@ -344,6 +354,4 @@ function _constraintByType(value, type) {
|
|
|
344
354
|
return { ideal: value };
|
|
345
355
|
}
|
|
346
356
|
}
|
|
347
|
-
|
|
348
|
-
//# sourceMappingURL=LocalStreamManager.js.map
|
|
349
|
-
//# sourceMappingURL=LocalStreamManager.js.map
|
|
357
|
+
//# sourceMappingURL=LocalStreamManager.js.map
|