mirror of https://github.com/OpenVidu/openvidu.git
openvidu-browser: rollback fix to Ionic iOS subscribers
parent
bb9c59deed
commit
edf5bf5fe9
|
@ -77,6 +77,14 @@ export class Session implements EventDispatcher {
|
||||||
*/
|
*/
|
||||||
remoteStreamsCreated: ObjMap<boolean> = {};
|
remoteStreamsCreated: ObjMap<boolean> = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hidden
|
||||||
|
*/
|
||||||
|
isFirstIonicIosSubscriber = true;
|
||||||
|
/**
|
||||||
|
* @hidden
|
||||||
|
*/
|
||||||
|
countDownForIonicIosSubscribersActive = true;
|
||||||
/**
|
/**
|
||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
|
@ -665,6 +673,11 @@ export class Session implements EventDispatcher {
|
||||||
streamEvent.callDefaultBehavior();
|
streamEvent.callDefaultBehavior();
|
||||||
|
|
||||||
delete this.remoteStreamsCreated[stream.streamId];
|
delete this.remoteStreamsCreated[stream.streamId];
|
||||||
|
|
||||||
|
if (Object.keys(this.remoteStreamsCreated).length === 0) {
|
||||||
|
this.isFirstIonicIosSubscriber = true;
|
||||||
|
this.countDownForIonicIosSubscribersActive = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
delete this.remoteConnections[connection.connectionId];
|
delete this.remoteConnections[connection.connectionId];
|
||||||
this.ee.emitEvent('connectionDestroyed', [new ConnectionEvent(false, this, 'connectionDestroyed', connection, msg.reason)]);
|
this.ee.emitEvent('connectionDestroyed', [new ConnectionEvent(false, this, 'connectionDestroyed', connection, msg.reason)]);
|
||||||
|
@ -734,6 +747,12 @@ export class Session implements EventDispatcher {
|
||||||
// Deleting the remote stream
|
// Deleting the remote stream
|
||||||
const streamId: string = connection.stream.streamId;
|
const streamId: string = connection.stream.streamId;
|
||||||
delete this.remoteStreamsCreated[streamId];
|
delete this.remoteStreamsCreated[streamId];
|
||||||
|
|
||||||
|
if (Object.keys(this.remoteStreamsCreated).length === 0) {
|
||||||
|
this.isFirstIonicIosSubscriber = true;
|
||||||
|
this.countDownForIonicIosSubscribersActive = true;
|
||||||
|
}
|
||||||
|
|
||||||
connection.removeStream(streamId);
|
connection.removeStream(streamId);
|
||||||
})
|
})
|
||||||
.catch(openViduError => {
|
.catch(openViduError => {
|
||||||
|
|
|
@ -718,7 +718,7 @@ export class Stream implements EventDispatcher {
|
||||||
reject('Error on publishVideo: ' + JSON.stringify(error));
|
reject('Error on publishVideo: ' + JSON.stringify(error));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.webRtcPeer.processAnswer(response.sdpAnswer)
|
this.webRtcPeer.processAnswer(response.sdpAnswer, false)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.streamId = response.id;
|
this.streamId = response.id;
|
||||||
this.creationTime = response.createdAt;
|
this.creationTime = response.createdAt;
|
||||||
|
@ -778,7 +778,19 @@ export class Stream implements EventDispatcher {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(new Error('Error on recvVideoFrom: ' + JSON.stringify(error)));
|
reject(new Error('Error on recvVideoFrom: ' + JSON.stringify(error)));
|
||||||
} else {
|
} else {
|
||||||
this.webRtcPeer.processAnswer(response.sdpAnswer).then(() => {
|
// Ios Ionic. Limitation: some bug in iosrtc cordova plugin makes it necessary
|
||||||
|
// to add a timeout before calling PeerConnection#setRemoteDescription during
|
||||||
|
// some time (400 ms) from the moment first subscriber stream is received
|
||||||
|
if (this.session.isFirstIonicIosSubscriber) {
|
||||||
|
this.session.isFirstIonicIosSubscriber = false;
|
||||||
|
setTimeout(() => {
|
||||||
|
// After 400 ms Ionic iOS subscribers won't need to run
|
||||||
|
// PeerConnection#setRemoteDescription after 250 ms timeout anymore
|
||||||
|
this.session.countDownForIonicIosSubscribersActive = false;
|
||||||
|
}, 400);
|
||||||
|
}
|
||||||
|
const needsTimeoutOnProcessAnswer = this.session.countDownForIonicIosSubscribersActive;
|
||||||
|
this.webRtcPeer.processAnswer(response.sdpAnswer, needsTimeoutOnProcessAnswer).then(() => {
|
||||||
this.remotePeerSuccessfullyEstablished();
|
this.remotePeerSuccessfullyEstablished();
|
||||||
this.initWebRtcStats();
|
this.initWebRtcStats();
|
||||||
resolve();
|
resolve();
|
||||||
|
|
|
@ -119,14 +119,14 @@ export class WebRtcPeer {
|
||||||
const pc1: any = this.pc;
|
const pc1: any = this.pc;
|
||||||
for (const sender of pc1.getLocalStreams()) {
|
for (const sender of pc1.getLocalStreams()) {
|
||||||
if (!videoSourceIsMediaStreamTrack) {
|
if (!videoSourceIsMediaStreamTrack) {
|
||||||
(<MediaStream>sender).stop();
|
sender.stop();
|
||||||
}
|
}
|
||||||
pc1.removeStream(sender);
|
pc1.removeStream(sender);
|
||||||
}
|
}
|
||||||
// Stop receivers deprecated
|
// Stop receivers deprecated
|
||||||
for (const receiver of pc1.getRemoteStreams()) {
|
for (const receiver of pc1.getRemoteStreams()) {
|
||||||
if (!!receiver.track) {
|
if (!!receiver.track) {
|
||||||
(<MediaStream>receiver).stop();
|
receiver.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -234,7 +234,7 @@ export class WebRtcPeer {
|
||||||
* Function invoked when a SDP answer is received. Final step in SDP negotiation, the peer
|
* Function invoked when a SDP answer is received. Final step in SDP negotiation, the peer
|
||||||
* just needs to set the answer as its remote description
|
* just needs to set the answer as its remote description
|
||||||
*/
|
*/
|
||||||
processAnswer(sdpAnswer: string): Promise<string> {
|
processAnswer(sdpAnswer: string, needsTimeoutOnProcessAnswer: boolean): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const answer: RTCSessionDescriptionInit = {
|
const answer: RTCSessionDescriptionInit = {
|
||||||
type: 'answer',
|
type: 'answer',
|
||||||
|
@ -246,7 +246,17 @@ export class WebRtcPeer {
|
||||||
reject('RTCPeerConnection is closed');
|
reject('RTCPeerConnection is closed');
|
||||||
}
|
}
|
||||||
if (platform['isIonicIos']) {
|
if (platform['isIonicIos']) {
|
||||||
|
// Ionic iOS platform
|
||||||
|
if (needsTimeoutOnProcessAnswer) {
|
||||||
|
// 400 ms have not elapsed yet since first remote stream triggered Stream#initWebRtcPeerReceive
|
||||||
|
setTimeout(() => {
|
||||||
|
console.info('setRemoteDescription run after timeout for Ionic iOS device');
|
||||||
this.pc.setRemoteDescription(new RTCSessionDescription(answer)).then(() => resolve()).catch(error => reject(error));
|
this.pc.setRemoteDescription(new RTCSessionDescription(answer)).then(() => resolve()).catch(error => reject(error));
|
||||||
|
}, 250);
|
||||||
|
} else {
|
||||||
|
// 400 ms have elapsed
|
||||||
|
this.pc.setRemoteDescription(new RTCSessionDescription(answer)).then(() => resolve()).catch(error => reject(error));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Rest of platforms
|
// Rest of platforms
|
||||||
this.pc.setRemoteDescription(answer).then(() => resolve()).catch(error => reject(error));
|
this.pc.setRemoteDescription(answer).then(() => resolve()).catch(error => reject(error));
|
||||||
|
|
Loading…
Reference in New Issue