OpenVidu.initPublisher() totally independent from Session

pull/32/head
pabloFuente 2018-03-02 11:03:45 +01:00
parent d5d383ce90
commit c2b3c46969
8 changed files with 25 additions and 16 deletions

View File

@ -19,7 +19,6 @@ import { OpenViduInternal } from '../OpenViduInternal/OpenViduInternal';
import { Session } from './Session'; import { Session } from './Session';
import { Publisher } from './Publisher'; import { Publisher } from './Publisher';
import { OpenViduError, OpenViduErrorName } from '../OpenViduInternal/OpenViduError'; import { OpenViduError, OpenViduErrorName } from '../OpenViduInternal/OpenViduError';
import { OutboundStreamOptions } from '../OpenViduInternal/index';
import { Stream } from '../OpenViduInternal/Stream'; import { Stream } from '../OpenViduInternal/Stream';
import { LocalRecorder } from '../OpenViduInternal/LocalRecorder'; import { LocalRecorder } from '../OpenViduInternal/LocalRecorder';

View File

@ -48,7 +48,7 @@ export class Publisher {
} }
destroy() { destroy() {
this.session.unpublish(this); if (!!this.session) this.session.unpublish(this);
this.stream.dispose(); this.stream.dispose();
this.stream.removeVideo(this.element); this.stream.removeVideo(this.element);
return this; return this;

View File

@ -102,6 +102,7 @@ export class Session {
private streamPublish(publisher: Publisher) { private streamPublish(publisher: Publisher) {
publisher.session = this; publisher.session = this;
this.connection.addStream(publisher.stream);
publisher.stream.publish(); publisher.stream.publish();
} }

View File

@ -22,7 +22,7 @@ export class Connection {
console.info( "'Connection' created (" + ( local ? "local" : "remote" ) + ")" + ( local ? "" : ", with 'connectionId' [" + (options ? options.id : '') + "] " )); console.info( "'Connection' created (" + ( local ? "local" : "remote" ) + ")" + ( local ? "" : ", with 'connectionId' [" + (options ? options.id : '') + "] " ));
if ( options ) { if ( options && !local ) {
this.connectionId = options.id; this.connectionId = options.id;
if (options.metadata) { if (options.metadata) {
@ -36,6 +36,7 @@ export class Connection {
} }
addStream( stream: Stream ) { addStream( stream: Stream ) {
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;
} }

View File

@ -15,6 +15,7 @@
* *
*/ */
import { SessionInternal, SessionOptions } from './SessionInternal'; import { SessionInternal, SessionOptions } from './SessionInternal';
import { Connection } from './Connection';
import { OpenViduError, OpenViduErrorName } from './OpenViduError'; import { OpenViduError, OpenViduErrorName } from './OpenViduError';
import { Stream, OutboundStreamOptions } from './Stream'; import { Stream, OutboundStreamOptions } from './Stream';
import * as RpcBuilder from '../KurentoUtils/kurento-jsonrpc'; import * as RpcBuilder from '../KurentoUtils/kurento-jsonrpc';
@ -45,7 +46,6 @@ export class OpenViduInternal {
if (newStream) { if (newStream) {
if (cameraOptions == null) { if (cameraOptions == null) {
cameraOptions = { cameraOptions = {
connection: this.session.getLocalParticipant(),
sendAudio: true, sendAudio: true,
sendVideo: true, sendVideo: true,
activeAudio: true, activeAudio: true,
@ -56,8 +56,6 @@ export class OpenViduInternal {
video: { width: { ideal: 1280 } } video: { width: { ideal: 1280 } }
} }
} }
} else {
cameraOptions.connection = this.session.getLocalParticipant();
} }
this.localStream = new Stream(this, true, this.session, cameraOptions); this.localStream = new Stream(this, true, this.session, cameraOptions);
} }

View File

@ -41,7 +41,7 @@ export class SessionInternal {
constructor(private openVidu: OpenViduInternal, sessionId: string) { constructor(private openVidu: OpenViduInternal, sessionId: string) {
this.sessionId = this.getUrlWithoutSecret(sessionId); this.sessionId = this.getUrlWithoutSecret(sessionId);
this.localParticipant = new Connection(this.openVidu, true, this); this.localParticipant = new Connection(this.openVidu, true, this);
if (!this.openVidu.getWsUri()) { if (!this.openVidu.getWsUri() && !!sessionId) {
this.processOpenViduUrl(sessionId); this.processOpenViduUrl(sessionId);
} }
} }
@ -214,6 +214,10 @@ export class SessionInternal {
this.updateSpeakerInterval = options.updateSpeakerInterval || 1500; this.updateSpeakerInterval = options.updateSpeakerInterval || 1500;
this.thresholdSpeaker = options.thresholdSpeaker || -50; this.thresholdSpeaker = options.thresholdSpeaker || -50;
this.activateUpdateMainSpeaker(); this.activateUpdateMainSpeaker();
if (!this.openVidu.getWsUri()) {
this.processOpenViduUrl(options.sessionId);
}
} }
getId() { getId() {

View File

@ -52,7 +52,6 @@ export interface InboundStreamOptions {
export interface OutboundStreamOptions { export interface OutboundStreamOptions {
activeAudio: boolean; activeAudio: boolean;
activeVideo: boolean; activeVideo: boolean;
connection: Connection;
dataChannel: boolean; dataChannel: boolean;
mediaConstraints: any; mediaConstraints: any;
sendAudio: boolean; sendAudio: boolean;
@ -93,6 +92,7 @@ export class Stream {
constructor(private openVidu: OpenViduInternal, private local: boolean, private room: SessionInternal, options: any) { constructor(private openVidu: OpenViduInternal, private local: boolean, private room: SessionInternal, options: any) {
if (options !== 'screen-options') { if (options !== 'screen-options') {
// Outbound stream (not screen share) or Inbound stream
if ('id' in options) { if ('id' in options) {
this.inboundOptions = options; this.inboundOptions = options;
} else { } else {
@ -100,11 +100,15 @@ export class Stream {
} }
this.streamId = (options.id != null) ? options.id : ((options.sendVideo) ? "CAMERA" : "MICRO"); this.streamId = (options.id != null) ? options.id : ((options.sendVideo) ? "CAMERA" : "MICRO");
this.typeOfVideo = (options.typeOfVideo != null) ? options.typeOfVideo : ''; 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 { } else {
// Outbound stream for screen share
this.isScreenRequested = true; this.isScreenRequested = true;
this.typeOfVideo = 'SCREEN'; this.typeOfVideo = 'SCREEN';
this.connection = this.room.getLocalParticipant();
} }
this.addEventListener('mediastream-updated', () => { this.addEventListener('mediastream-updated', () => {
if (this.video) this.video.srcObject = this.mediaStream; if (this.video) this.video.srcObject = this.mediaStream;
@ -336,8 +340,6 @@ export class Stream {
requestCameraAccess(callback: Callback<Stream>) { requestCameraAccess(callback: Callback<Stream>) {
this.connection.addStream(this);
let constraints = this.outboundOptions.mediaConstraints; let constraints = this.outboundOptions.mediaConstraints;
/*let constraints2 = { /*let constraints2 = {

View File

@ -140,8 +140,9 @@ export class WebRtcStats {
"@timestamp": new Date(stat.timestamp).toISOString(), "@timestamp": new Date(stat.timestamp).toISOString(),
"exec": instrumentation.exec, "exec": instrumentation.exec,
"component": instrumentation.component, "component": instrumentation.component,
"stream": "webRtc",
"type": metricId, "type": metricId,
"stream_type": "composed_metric", "stream_type": "composed_metrics",
"units": units "units": units
} }
json[metricId] = metrics; json[metricId] = metrics;
@ -179,8 +180,9 @@ export class WebRtcStats {
"@timestamp": new Date(stat.timestamp).toISOString(), "@timestamp": new Date(stat.timestamp).toISOString(),
"exec": instrumentation.exec, "exec": instrumentation.exec,
"component": instrumentation.component, "component": instrumentation.component,
"stream": "webRtc",
"type": metricId, "type": metricId,
"stream_type": "composed_metric", "stream_type": "composed_metrics",
"units": units "units": units
} }
json[metricId] = metrics; json[metricId] = metrics;
@ -232,8 +234,9 @@ export class WebRtcStats {
"@timestamp": new Date(stat.timestamp).toISOString(), "@timestamp": new Date(stat.timestamp).toISOString(),
"exec": instrumentation.exec, "exec": instrumentation.exec,
"component": instrumentation.component, "component": instrumentation.component,
"stream": "webRtc",
"type": metricId, "type": metricId,
"stream_type": "composed_metric", "stream_type": "composed_metrics",
"units": units "units": units
} }
json[metricId] = metrics; json[metricId] = metrics;
@ -265,8 +268,9 @@ export class WebRtcStats {
"@timestamp": new Date(stat.timestamp).toISOString(), "@timestamp": new Date(stat.timestamp).toISOString(),
"exec": instrumentation.exec, "exec": instrumentation.exec,
"component": instrumentation.component, "component": instrumentation.component,
"stream": "webRtc",
"type": metricId, "type": metricId,
"stream_type": "composed_metric", "stream_type": "composed_metrics",
"units": units "units": units
} }
json[metricId] = metrics; json[metricId] = metrics;