@osimatic/helpers-js 1.1.35 → 1.1.37
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/package.json +1 -1
- package/web_rtc.js +9 -12
package/package.json
CHANGED
package/web_rtc.js
CHANGED
|
@@ -12,7 +12,7 @@ class WebRTC {
|
|
|
12
12
|
this.signalingBus = signalingBus;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
static offer(videoBroadcasterId, stream, iceCandidateCallback,
|
|
15
|
+
static offer(videoBroadcasterId, stream, iceCandidateCallback, connectionStateChangeCallback) {
|
|
16
16
|
return new Promise(async (resolve, reject) => {
|
|
17
17
|
try {
|
|
18
18
|
let { username, password } = this.getTurnCredentials();
|
|
@@ -26,19 +26,16 @@ class WebRTC {
|
|
|
26
26
|
}]
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
peerConn.onnegotiationneeded = async () => {
|
|
30
|
-
await peerConn.setLocalDescription(await peerConn.createOffer());
|
|
31
|
-
this.signalingBus.subscribe('answer', (payload) => peerConn.setRemoteDescription(payload.description));
|
|
32
|
-
this.signalingBus.subscribe('candidate', (payload) => peerConn.addIceCandidate(new RTCIceCandidate(payload.candidate)));
|
|
33
|
-
this.signalingBus.publish('offer', { id: videoBroadcasterId, description: peerConn.localDescription });
|
|
34
|
-
};
|
|
35
|
-
|
|
36
29
|
peerConn.onconnectionstatechange = (event) => connectionStateChangeCallback(event, peerConn.connectionState);
|
|
37
30
|
peerConn.onicecandidate = (event) => iceCandidateCallback(event);
|
|
38
|
-
peerConn.onicecandidateerror = (event) => onIceCandidateErrorCallback(event.errorCode, event.errorText);
|
|
39
31
|
|
|
40
32
|
stream.getTracks().forEach(track => peerConn.addTrack(track, stream));
|
|
41
|
-
|
|
33
|
+
await peerConn.setLocalDescription(await peerConn.createOffer());
|
|
34
|
+
|
|
35
|
+
this.signalingBus.subscribe('answer', (payload) => peerConn.setRemoteDescription(payload.description));
|
|
36
|
+
this.signalingBus.subscribe('candidate', (payload) => peerConn.addIceCandidate(new RTCIceCandidate(payload.candidate)));
|
|
37
|
+
this.signalingBus.publish('offer', { id: videoBroadcasterId, description: peerConn.localDescription });
|
|
38
|
+
|
|
42
39
|
resolve(peerConn);
|
|
43
40
|
} catch (error) {
|
|
44
41
|
console.error(error);
|
|
@@ -47,7 +44,7 @@ class WebRTC {
|
|
|
47
44
|
});
|
|
48
45
|
}
|
|
49
46
|
|
|
50
|
-
static answer(videoBroadcasterId, remoteDescription, onTrackCallback, iceCandidateCallback,
|
|
47
|
+
static answer(videoBroadcasterId, remoteDescription, onTrackCallback, iceCandidateCallback, connectionStateChangeCallback) {
|
|
51
48
|
return new Promise(async (resolve, reject) => {
|
|
52
49
|
try {
|
|
53
50
|
let { username, password } = this.getTurnCredentials();
|
|
@@ -63,11 +60,11 @@ class WebRTC {
|
|
|
63
60
|
|
|
64
61
|
peerConn.onconnectionstatechange = (event) => connectionStateChangeCallback(event, peerConn.connectionState);
|
|
65
62
|
peerConn.onicecandidate = async (event) => iceCandidateCallback(event);
|
|
66
|
-
peerConn.onicecandidateerror = (event) => onIceCandidateErrorCallback(event.errorCode, event.errorText);
|
|
67
63
|
peerConn.ontrack = (event) => onTrackCallback(event.streams);
|
|
68
64
|
|
|
69
65
|
peerConn.setRemoteDescription(new RTCSessionDescription(remoteDescription));
|
|
70
66
|
await peerConn.setLocalDescription(await peerConn.createAnswer());
|
|
67
|
+
|
|
71
68
|
this.signalingBus.subscribe('candidate', (payload) => peerConn.addIceCandidate(new RTCIceCandidate(payload.candidate)));
|
|
72
69
|
this.signalingBus.publish('answer', { id: videoBroadcasterId, description: peerConn.localDescription });
|
|
73
70
|
|