mirror of https://github.com/OpenVidu/openvidu.git
openvidu-browser minor refactoring
parent
a116c2fee5
commit
c63e02bd66
|
@ -26,10 +26,10 @@ export class Session {
|
|||
// Listens to the deactivation of the default behaviour upon the disconnection of a Session
|
||||
this.session.addEventListener('session-disconnected-default', () => {
|
||||
let s: Stream;
|
||||
for (s of this.openVidu.openVidu.getRemoteStreams()) {
|
||||
s.removeVideo();
|
||||
for (let streamId in this.session.getRemoteStreams()) {
|
||||
this.session.getRemoteStreams()[streamId].removeVideo();
|
||||
}
|
||||
if (this.connection) {
|
||||
if (this.connection && (Object.keys(this.connection.getStreams()).length > 0)) {
|
||||
for (let streamId in this.connection.getStreams()) {
|
||||
this.connection.getStreams()[streamId].removeVideo();
|
||||
}
|
||||
|
|
|
@ -38,12 +38,12 @@ export class Connection {
|
|||
addStream( stream: Stream ) {
|
||||
stream.connection = this;
|
||||
this.streams[stream.streamId] = stream;
|
||||
this.room.getStreams()[stream.streamId] = stream;
|
||||
//this.room.getStreams()[stream.streamId] = stream;
|
||||
}
|
||||
|
||||
removeStream( key: string ) {
|
||||
delete this.streams[key];
|
||||
delete this.room.getStreams()[key];
|
||||
//delete this.room.getStreams()[key];
|
||||
delete this.inboundStreamsOpts;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ export class OpenViduInternal {
|
|||
private rpcParams: any;
|
||||
private callback: Callback<OpenViduInternal>;
|
||||
private localStream: Stream;
|
||||
private remoteStreams: Stream[] = [];
|
||||
private secret: string;
|
||||
private recorder: boolean = false;
|
||||
|
||||
|
@ -148,9 +147,6 @@ export class OpenViduInternal {
|
|||
return this.localStream;
|
||||
}
|
||||
|
||||
getRemoteStreams() {
|
||||
return this.remoteStreams;
|
||||
}
|
||||
/* NEW METHODS */
|
||||
|
||||
getWsUri() {
|
||||
|
|
|
@ -5,6 +5,8 @@ import { Publisher } from '../OpenVidu/Publisher';
|
|||
|
||||
import EventEmitter = require('wolfy87-eventemitter');
|
||||
|
||||
type ObjMap<T> = { [s: string]: T; }
|
||||
|
||||
const SECRET_PARAM = '?secret=';
|
||||
const RECORDER_PARAM = '&recorder=';
|
||||
|
||||
|
@ -28,7 +30,7 @@ export class SessionInternal {
|
|||
private id: string;
|
||||
private sessionId: string;
|
||||
private ee = new EventEmitter();
|
||||
private streams = {};
|
||||
private remoteStreams: ObjMap<Stream> = {};
|
||||
private participants = {};
|
||||
private publishersSpeaking: Connection[] = [];
|
||||
private connected = false;
|
||||
|
@ -129,7 +131,7 @@ export class SessionInternal {
|
|||
|
||||
if (this.localParticipant) {
|
||||
if (Object.keys(this.localParticipant.getStreams()).some(streamId =>
|
||||
this.streams[streamId].isDataChannelEnabled())) {
|
||||
this.remoteStreams[streamId].isDataChannelEnabled())) {
|
||||
joinParams.dataChannels = true;
|
||||
}
|
||||
}
|
||||
|
@ -191,8 +193,8 @@ export class SessionInternal {
|
|||
for (let stream of roomEvent.streams) {
|
||||
this.ee.emitEvent('streamCreated', [{ stream }]);
|
||||
|
||||
// Adding the remote stream to the OpenVidu object
|
||||
this.openVidu.getRemoteStreams().push(stream);
|
||||
// Store the remote stream
|
||||
this.remoteStreams[stream.streamId] = stream;
|
||||
}
|
||||
|
||||
callback(undefined);
|
||||
|
@ -311,7 +313,7 @@ export class SessionInternal {
|
|||
for (let key in streams) {
|
||||
let stream = streams[key];
|
||||
|
||||
if (!this.streams[stream.streamId]) {
|
||||
if (!this.remoteStreams[stream.streamId]) {
|
||||
// Avoid race condition between stream.subscribe() in "onParticipantPublished" and in "joinRoom" rpc callback
|
||||
// This condition is false if openvidu-server sends "participantPublished" event to a subscriber participant that has
|
||||
// already subscribed to certain stream in the callback of "joinRoom" method
|
||||
|
@ -321,8 +323,8 @@ export class SessionInternal {
|
|||
}
|
||||
this.ee.emitEvent('streamCreated', [{ stream }]);
|
||||
|
||||
// Adding the remote stream to the OpenVidu object
|
||||
this.openVidu.getRemoteStreams().push(stream);
|
||||
// Store the remote stream
|
||||
this.remoteStreams[stream.streamId] = stream;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -343,14 +345,12 @@ export class SessionInternal {
|
|||
stream: streams[key]
|
||||
}]);
|
||||
|
||||
// Deleting the removed stream from the OpenVidu object
|
||||
let index = this.openVidu.getRemoteStreams().indexOf(streams[key]);
|
||||
let stream = this.openVidu.getRemoteStreams()[index];
|
||||
|
||||
// Deleting the remote stream
|
||||
let streamId: string = streams[key].streamId;
|
||||
let stream: Stream = this.remoteStreams[streamId];
|
||||
|
||||
stream.dispose();
|
||||
this.openVidu.getRemoteStreams().splice(index, 1);
|
||||
delete this.streams[stream.streamId];
|
||||
delete this.remoteStreams[stream.streamId];
|
||||
connection.removeStream(stream.streamId);
|
||||
|
||||
}
|
||||
|
@ -391,7 +391,6 @@ export class SessionInternal {
|
|||
let connection: Connection = this.participants[msg.name];
|
||||
|
||||
if (connection !== undefined) {
|
||||
delete this.participants[msg.name];
|
||||
|
||||
this.ee.emitEvent('participant-left', [{
|
||||
connection: connection
|
||||
|
@ -407,13 +406,15 @@ export class SessionInternal {
|
|||
stream: streams[key]
|
||||
}]);
|
||||
|
||||
// Deleting the removed stream from the OpenVidu object
|
||||
let index = this.openVidu.getRemoteStreams().indexOf(streams[key]);
|
||||
this.openVidu.getRemoteStreams().splice(index, 1);
|
||||
// Deleting the remote stream
|
||||
let streamId: string = streams[key].streamId;
|
||||
delete this.remoteStreams[streamId];
|
||||
}
|
||||
|
||||
connection.dispose();
|
||||
|
||||
delete this.participants[msg.name];
|
||||
|
||||
this.ee.emitEvent('connectionDestroyed', [{
|
||||
connection: connection
|
||||
}]);
|
||||
|
@ -618,8 +619,8 @@ export class SessionInternal {
|
|||
}
|
||||
}
|
||||
|
||||
getStreams() {
|
||||
return this.streams;
|
||||
getRemoteStreams() {
|
||||
return this.remoteStreams;
|
||||
}
|
||||
|
||||
addParticipantSpeaking(participantId) {
|
||||
|
|
Loading…
Reference in New Issue