Fix sharing peer connection
This commit is contained in:
parent
c03dd4c551
commit
2ee6d43274
3 changed files with 49 additions and 28 deletions
|
@ -13,6 +13,8 @@ export class ScreenSharingPeer extends Peer {
|
|||
* Whether this connection is currently receiving a video stream from a remote user.
|
||||
*/
|
||||
private isReceivingStream:boolean = false;
|
||||
public toClose: boolean = false;
|
||||
public _connected: boolean = false;
|
||||
|
||||
constructor(private userId: number, initiator: boolean, private connection: RoomConnection) {
|
||||
super({
|
||||
|
@ -42,6 +44,8 @@ export class ScreenSharingPeer extends Peer {
|
|||
});
|
||||
|
||||
this.on('close', () => {
|
||||
this._connected = false;
|
||||
this.toClose = true;
|
||||
this.destroy();
|
||||
});
|
||||
|
||||
|
@ -62,11 +66,16 @@ export class ScreenSharingPeer extends Peer {
|
|||
});
|
||||
|
||||
this.on('connect', () => {
|
||||
this._connected = true;
|
||||
// FIXME: we need to put the loader on the screen sharing connection
|
||||
mediaManager.isConnected("" + this.userId);
|
||||
console.info(`connect => ${this.userId}`);
|
||||
});
|
||||
|
||||
this.once('finish', () => {
|
||||
this._onFinish();
|
||||
});
|
||||
|
||||
this.pushScreenSharingToRemoteUser();
|
||||
}
|
||||
|
||||
|
@ -100,6 +109,10 @@ export class ScreenSharingPeer extends Peer {
|
|||
|
||||
public destroy(error?: Error): void {
|
||||
try {
|
||||
this._connected = false
|
||||
if(!this.toClose){
|
||||
return;
|
||||
}
|
||||
mediaManager.removeActiveScreenSharingVideo("" + this.userId);
|
||||
// FIXME: I don't understand why "Closing connection with" message is displayed TWICE before "Nb users in peerConnectionArray"
|
||||
// I do understand the method closeConnection is called twice, but I don't understand how they manage to run in parallel.
|
||||
|
@ -111,6 +124,18 @@ export class ScreenSharingPeer extends Peer {
|
|||
}
|
||||
}
|
||||
|
||||
_onFinish () {
|
||||
if (this.destroyed) return
|
||||
const destroySoon = () => {
|
||||
this.destroy();
|
||||
}
|
||||
if (this._connected) {
|
||||
destroySoon();
|
||||
} else {
|
||||
this.once('connect', destroySoon);
|
||||
}
|
||||
}
|
||||
|
||||
private pushScreenSharingToRemoteUser() {
|
||||
const localScreenCapture: MediaStream | null = mediaManager.localScreenCapture;
|
||||
if(!localScreenCapture){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue