diff --git a/openvidu-browser/ts/OpenVidu/OpenVidu.ts b/openvidu-browser/ts/OpenVidu/OpenVidu.ts index b8cb72fa..80b39710 100644 --- a/openvidu-browser/ts/OpenVidu/OpenVidu.ts +++ b/openvidu-browser/ts/OpenVidu/OpenVidu.ts @@ -19,7 +19,6 @@ import { OpenViduInternal } from '../OpenViduInternal/OpenViduInternal'; import { Session } from './Session'; import { Publisher } from './Publisher'; import { OpenViduError, OpenViduErrorName } from '../OpenViduInternal/OpenViduError'; -import { OutboundStreamOptions } from '../OpenViduInternal/index'; import { Stream } from '../OpenViduInternal/Stream'; import { LocalRecorder } from '../OpenViduInternal/LocalRecorder'; diff --git a/openvidu-browser/ts/OpenVidu/Publisher.ts b/openvidu-browser/ts/OpenVidu/Publisher.ts index d3180075..946ce9ce 100644 --- a/openvidu-browser/ts/OpenVidu/Publisher.ts +++ b/openvidu-browser/ts/OpenVidu/Publisher.ts @@ -48,7 +48,7 @@ export class Publisher { } destroy() { - this.session.unpublish(this); + if (!!this.session) this.session.unpublish(this); this.stream.dispose(); this.stream.removeVideo(this.element); return this; diff --git a/openvidu-browser/ts/OpenVidu/Session.ts b/openvidu-browser/ts/OpenVidu/Session.ts index ecf69f6d..f59417a7 100644 --- a/openvidu-browser/ts/OpenVidu/Session.ts +++ b/openvidu-browser/ts/OpenVidu/Session.ts @@ -102,6 +102,7 @@ export class Session { private streamPublish(publisher: Publisher) { publisher.session = this; + this.connection.addStream(publisher.stream); publisher.stream.publish(); } diff --git a/openvidu-browser/ts/OpenViduInternal/Connection.ts b/openvidu-browser/ts/OpenViduInternal/Connection.ts index faef6e01..c5e0dc79 100644 --- a/openvidu-browser/ts/OpenViduInternal/Connection.ts +++ b/openvidu-browser/ts/OpenViduInternal/Connection.ts @@ -22,7 +22,7 @@ export class Connection { console.info( "'Connection' created (" + ( local ? "local" : "remote" ) + ")" + ( local ? "" : ", with 'connectionId' [" + (options ? options.id : '') + "] " )); - if ( options ) { + if ( options && !local ) { this.connectionId = options.id; if (options.metadata) { @@ -36,6 +36,7 @@ export class Connection { } addStream( stream: Stream ) { + stream.connection = this; this.streams[stream.streamId] = stream; this.room.getStreams()[stream.streamId] = stream; } diff --git a/openvidu-browser/ts/OpenViduInternal/OpenViduInternal.ts b/openvidu-browser/ts/OpenViduInternal/OpenViduInternal.ts index 5a84aaf4..ecb57a92 100644 --- a/openvidu-browser/ts/OpenViduInternal/OpenViduInternal.ts +++ b/openvidu-browser/ts/OpenViduInternal/OpenViduInternal.ts @@ -15,6 +15,7 @@ * */ import { SessionInternal, SessionOptions } from './SessionInternal'; +import { Connection } from './Connection'; import { OpenViduError, OpenViduErrorName } from './OpenViduError'; import { Stream, OutboundStreamOptions } from './Stream'; import * as RpcBuilder from '../KurentoUtils/kurento-jsonrpc'; @@ -45,7 +46,6 @@ export class OpenViduInternal { if (newStream) { if (cameraOptions == null) { cameraOptions = { - connection: this.session.getLocalParticipant(), sendAudio: true, sendVideo: true, activeAudio: true, @@ -56,8 +56,6 @@ export class OpenViduInternal { video: { width: { ideal: 1280 } } } } - } else { - cameraOptions.connection = this.session.getLocalParticipant(); } this.localStream = new Stream(this, true, this.session, cameraOptions); } diff --git a/openvidu-browser/ts/OpenViduInternal/SessionInternal.ts b/openvidu-browser/ts/OpenViduInternal/SessionInternal.ts index 50c8672c..fb832c09 100644 --- a/openvidu-browser/ts/OpenViduInternal/SessionInternal.ts +++ b/openvidu-browser/ts/OpenViduInternal/SessionInternal.ts @@ -41,7 +41,7 @@ export class SessionInternal { constructor(private openVidu: OpenViduInternal, sessionId: string) { this.sessionId = this.getUrlWithoutSecret(sessionId); this.localParticipant = new Connection(this.openVidu, true, this); - if (!this.openVidu.getWsUri()) { + if (!this.openVidu.getWsUri() && !!sessionId) { this.processOpenViduUrl(sessionId); } } @@ -214,6 +214,10 @@ export class SessionInternal { this.updateSpeakerInterval = options.updateSpeakerInterval || 1500; this.thresholdSpeaker = options.thresholdSpeaker || -50; this.activateUpdateMainSpeaker(); + + if (!this.openVidu.getWsUri()) { + this.processOpenViduUrl(options.sessionId); + } } getId() { diff --git a/openvidu-browser/ts/OpenViduInternal/Stream.ts b/openvidu-browser/ts/OpenViduInternal/Stream.ts index 8ef8a1b5..a828333e 100644 --- a/openvidu-browser/ts/OpenViduInternal/Stream.ts +++ b/openvidu-browser/ts/OpenViduInternal/Stream.ts @@ -52,7 +52,6 @@ export interface InboundStreamOptions { export interface OutboundStreamOptions { activeAudio: boolean; activeVideo: boolean; - connection: Connection; dataChannel: boolean; mediaConstraints: any; sendAudio: boolean; @@ -93,6 +92,7 @@ export class Stream { constructor(private openVidu: OpenViduInternal, private local: boolean, private room: SessionInternal, options: any) { if (options !== 'screen-options') { + // Outbound stream (not screen share) or Inbound stream if ('id' in options) { this.inboundOptions = options; } else { @@ -100,11 +100,15 @@ export class Stream { } this.streamId = (options.id != null) ? options.id : ((options.sendVideo) ? "CAMERA" : "MICRO"); this.typeOfVideo = (options.typeOfVideo != null) ? options.typeOfVideo : ''; - this.connection = options.connection; + + if ('recvAudio' in options) { + // Set Connection for an Inbound stream (for Outbound streams will be set on Session.Publish(Publisher)) + this.connection = options.connection; + } } else { + // Outbound stream for screen share this.isScreenRequested = true; this.typeOfVideo = 'SCREEN'; - this.connection = this.room.getLocalParticipant(); } this.addEventListener('mediastream-updated', () => { if (this.video) this.video.srcObject = this.mediaStream; @@ -336,8 +340,6 @@ export class Stream { requestCameraAccess(callback: Callback) { - this.connection.addStream(this); - let constraints = this.outboundOptions.mediaConstraints; /*let constraints2 = { diff --git a/openvidu-browser/ts/OpenViduInternal/WebRtcStats.ts b/openvidu-browser/ts/OpenViduInternal/WebRtcStats.ts index 72ee9994..e806473d 100644 --- a/openvidu-browser/ts/OpenViduInternal/WebRtcStats.ts +++ b/openvidu-browser/ts/OpenViduInternal/WebRtcStats.ts @@ -140,8 +140,9 @@ export class WebRtcStats { "@timestamp": new Date(stat.timestamp).toISOString(), "exec": instrumentation.exec, "component": instrumentation.component, + "stream": "webRtc", "type": metricId, - "stream_type": "composed_metric", + "stream_type": "composed_metrics", "units": units } json[metricId] = metrics; @@ -179,8 +180,9 @@ export class WebRtcStats { "@timestamp": new Date(stat.timestamp).toISOString(), "exec": instrumentation.exec, "component": instrumentation.component, + "stream": "webRtc", "type": metricId, - "stream_type": "composed_metric", + "stream_type": "composed_metrics", "units": units } json[metricId] = metrics; @@ -232,8 +234,9 @@ export class WebRtcStats { "@timestamp": new Date(stat.timestamp).toISOString(), "exec": instrumentation.exec, "component": instrumentation.component, + "stream": "webRtc", "type": metricId, - "stream_type": "composed_metric", + "stream_type": "composed_metrics", "units": units } json[metricId] = metrics; @@ -265,8 +268,9 @@ export class WebRtcStats { "@timestamp": new Date(stat.timestamp).toISOString(), "exec": instrumentation.exec, "component": instrumentation.component, + "stream": "webRtc", "type": metricId, - "stream_type": "composed_metric", + "stream_type": "composed_metrics", "units": units } json[metricId] = metrics;