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