Fixed parameterization of name and adapter on mcs-core

It was broken on merging upstream
This commit is contained in:
prlanzarin 2018-04-16 04:49:11 +00:00
parent 1523305b4b
commit 10fe1d6a00
3 changed files with 32 additions and 14 deletions

View File

@ -84,7 +84,7 @@ module.exports = class MediaController {
}
}
publishnsubscribe (userId, sourceId, sdp, params) {
publishnsubscribe (userId, sourceId, sdp, params = {}) {
return new Promise(async (resolve, reject) => {
Logger.info("[mcs-controller] PublishAndSubscribe from user", userId, "to source", sourceId);
Logger.debug("[mcs-controler] PublishAndSubscribe descriptor is", params.descriptor);
@ -121,7 +121,7 @@ module.exports = class MediaController {
});
}
publish (userId, roomId, type, params) {
publish (userId, roomId, type, params = {}) {
return new Promise(async (resolve, reject) => {
Logger.info("[mcs-controller] Publish from user", userId, "to room", roomId);
Logger.debug("[mcs-controler] Publish descriptor is", params.descriptor);
@ -136,11 +136,11 @@ module.exports = class MediaController {
switch (type) {
case "RtpEndpoint":
case "WebRtcEndpoint":
session = user.addSdp(params.descriptor, type);
session = user.addSdp(params.descriptor, type, params.adapter, params.name);
answer = await user.startSession(session.id);
break;
case "URI":
session = user.addUri(params.descriptor, type);
session = user.addUri(params.descriptor, type, params.adapter, params.name);
answer = await user.startSession(session.id);
break;
@ -169,7 +169,7 @@ module.exports = class MediaController {
});
}
subscribe (userId, sourceId, type, params) {
subscribe (userId, sourceId, type, params = {}) {
return new Promise(async (resolve, reject) => {
Logger.info("[mcs-controller] Subscribe from user", userId, "to source", sourceId);
Logger.debug("[mcs-controler] Subscribe descriptor is", params.descriptor);
@ -190,7 +190,7 @@ module.exports = class MediaController {
switch (type) {
case "RtpEndpoint":
case "WebRtcEndpoint":
session = user.addSdp(params.descriptor, type);
session = user.addSdp(params.descriptor, type, params.adapter, params.name);
answer = await user.startSession(session.id);
await sourceSession.connect(session._mediaElement);
@ -198,10 +198,9 @@ module.exports = class MediaController {
Logger.info("[mcs-controller] Updated", sourceSession.id, "subscribers list to", sourceSession.subscribedSessions);
break;
case "URI":
session = user.addUri(params.descriptor, type);
session = user.addUri(params.descriptor, type, params.adapter, params.name);
answer = await user.startSession(session.id);
await sourceSession.connect(session._mediaElement);
break;
default: return reject(new Error("[mcs-controller] Invalid media type"));

View File

@ -7,14 +7,15 @@
const C = require('../constants/Constants');
const rid = require('readable-id');
const MediaServer = require('../media/media-server');
const Kurento = require('../adapters/kurento');
const Freeswitch = require('../adapters/freeswitch/freeswitch');
const config = require('config');
const kurentoUrl = config.get('kurentoUrl');
const Logger = require('../../../utils/Logger');
const isError = require('../utils/util').isError;
module.exports = class MediaSession {
constructor(emitter, room, type, options = {}) {
constructor(emitter, room, type = 'WebRtcEndpoint', adapter = C.STRING.KURENTO, name = C.STRING.DEFAULT_NAME, options = {}) {
this.id = rid();
this.room = room;
this.emitter = emitter;
@ -23,7 +24,9 @@ module.exports = class MediaSession {
this._MediaServer = new MediaServer(kurentoUrl);
this._mediaElement;
this.subscribedSessions = [];
this._options = options;
this._adapter = adapter;
this._MediaServer = MediaSession.getAdapter(adapter);
this._name = name;this._options = options;
this.eventQueue = [];
}
@ -46,6 +49,7 @@ module.exports = class MediaSession {
this.emitter.emit(C.EVENT.MEDIA_STATE.MEDIA_EVENT+this.id, event);
}
});
this._MediaServer.trackMediaState(this._mediaElement, this._type);
this._MediaServer.on(C.ERROR.MEDIA_SERVER_OFFLINE, () => {
@ -126,6 +130,23 @@ module.exports = class MediaSession {
}
}
static getAdapter (adapter) {
let obj = null;
Logger.info("[SdpSession] Session is using the", adapter, "adapter");
switch (adapter) {
case C.STRING.KURENTO:
obj = new Kurento(kurentoUrl);
break;
case C.STRING.FREESWITCH:
obj = new Freeswitch();
break;
default: Logger.warn("[SdpSession] Invalid adapter", this.adapter); }
return obj;
}
_handleError (error) {
Logger.error("[mcs-media-session] SFU MediaSession received an error", error);
// Checking if the error needs to be wrapped into a JS Error instance

View File

@ -8,7 +8,6 @@
const C = require('../constants/Constants');
const SdpWrapper = require('../utils/SdpWrapper');
const rid = require('readable-id');
const MediaServer = require('../media/media-server');
const MediaSession = require('./MediaSession');
const config = require('config');
const kurentoUrl = config.get('kurentoUrl');
@ -31,8 +30,7 @@ module.exports = class SdpSession extends MediaSession {
async process () {
try {
const answer = await this._MediaServer.processOffer(this._mediaElement, this._sdp.getPlainSdp());
const answer = await this._MediaServer.processOffer(this._mediaElement, this._sdp.getPlainSdp(), {name: this._name});
if (this._type === 'WebRtcEndpoint') {
this._MediaServer.gatherCandidates(this._mediaElement);
}