Fixed bitrate methods and ICE calls in screenshare

This commit is contained in:
prlanzarin 2018-06-04 15:07:20 +00:00
parent a9073c7c45
commit bccb8d51a8
6 changed files with 40 additions and 33 deletions

View File

@ -41,11 +41,13 @@ exports.EVENT.SERVER_STATE = "ServerState"
// Error codes
exports.ERROR = {};
exports.ERROR.MEDIA_SERVER_OFFLINE = "1000";
exports.ERROR.MEDIA_SERVER_ERROR = "1001";
exports.ERROR.USER_NOT_FOUND = "1100";
exports.ERROR.MEDIA_NOT_FOUND = "1101";
exports.ERROR.INVALID_SDP = "1102";
exports.ERROR.CONNECTION_ERROR = "CONNECTION_ERROR";
exports.ERROR.MEDIA_SERVER_OFFLINE = "MEDIA_SERVER_OFFLINE";
exports.ERROR.MEDIA_SERVER_ERROR = "MEDIA_SERVER_ERROR";
exports.ERROR.ROOM_NOT_FOUND = "ROOM_NOT_FOUND";
exports.ERROR.USER_NOT_FOUND = "USER_NOT_FOUND";
exports.ERROR.MEDIA_NOT_FOUND = "MEDIA_NOT_FOUND";
exports.ERROR.SDP_ERROR = "SDP_ERROR";
// RTP params
exports.SDP = {};

View File

@ -193,7 +193,7 @@ module.exports = class MediaController {
session.sessionStarted();
Logger.info("[mcs-controller] Updated", source.id, "subscribers list to", source.subscribedSessions);
break;
default:
default:
return reject(new Error("[mcs-controller] Invalid media type"));
}
}

View File

@ -403,30 +403,30 @@ module.exports = class MediaServer extends EventEmitter {
let mediaElement = this._mediaElements[elementId];
if (mediaElement) {
endpoint.setMinVideoRecvBandwidth(min);
endpoint.setMaxVideoRecvBandwidth(max);
mediaElement.setMinVideoRecvBandwidth(min);
mediaElement.setMaxVideoRecvBandwidth(max);
} else {
return ("[mcs-media] There is no element " + elementId);
}
}
setOutputBandwidth (endpoint, min, max) {
setOutputBandwidth (elementId, min, max) {
let mediaElement = this._mediaElements[elementId];
if (mediaElement) {
endpoint.setMinVideoSendBandwidth(min);
endpoint.setMaxVideoSendBandwidth(max);
mediaElement.setMinVideoSendBandwidth(min);
mediaElement.setMaxVideoSendBandwidth(max);
} else {
return ("[mcs-media] There is no element " + elementId );
}
}
setOutputBitrate (endpoint, min, max) {
setOutputBitrate (elementId, min, max) {
let mediaElement = this._mediaElements[elementId];
if (mediaElement) {
endpoint.setMinOutputBitrate(min);
endpoint.setMaxOutputBitrate(max);
mediaElement.setMinOutputBitrate(min);
mediaElement.setMaxOutputBitrate(max);
} else {
return ("[mcs-media] There is no element " + elementId);
}

View File

@ -12,6 +12,7 @@ const MediaServer = require('../media/media-server');
const MediaSession = require('./MediaSession');
const config = require('config');
const kurentoUrl = config.get('kurentoUrl');
const kurentoIp = config.get('kurentoIp');
const Logger = require('../../../utils/Logger');
module.exports = class SdpSession extends MediaSession {
@ -35,6 +36,7 @@ module.exports = class SdpSession extends MediaSession {
const answer = await this._MediaServer.processOffer(this._mediaElement, this._sdp.getPlainSdp());
if (this._type != 'WebRtcEndpoint') {
this._sdp.replaceServerIpv4(kurentoIp);
return resolve(answer);
}

View File

@ -34,7 +34,7 @@ module.exports.videoConfiguration = {
codecName: 'H264',
frameRate: '30.000000',
codecRate: '90000'
};
};
module.exports.generateStreamUrl = function (address, meeting, path) {
return "rtmp://" + address + "/video-broadcast/" + meeting + "/" + path;

View File

@ -58,14 +58,14 @@ module.exports = class Screenshare extends EventEmitter {
});
}
onIceCandidate (candidate, role, callerName) {
async onIceCandidate (candidate, role, callerName) {
Logger.debug("[screenshare] onIceCandidate", role, callerName, candidate);
switch (role) {
case C.SEND_ROLE:
if (this._presenterEndpoint) {
try {
this.flushCandidatesQueue(this._presenterEndpoint, this._presenterCandidatesQueue);
this.mcs.addIceCandidate(this._presenterEndpoint, candidate);
await this.flushCandidatesQueue(this._presenterEndpoint, this._presenterCandidatesQueue);
await this.mcs.addIceCandidate(this._presenterEndpoint, candidate);
} catch (err) {
Logger.error("[screenshare] ICE candidate could not be added to media controller.", err);
}
@ -77,8 +77,8 @@ module.exports = class Screenshare extends EventEmitter {
let endpoint = this._viewersEndpoint[callerName];
if (endpoint) {
try {
this.flushCandidatesQueue(endpoint, this._viewersCandidatesQueue[callerName]);
this.mcs.addIceCandidate(endpoint, candidate);
await this.flushCandidatesQueue(endpoint, this._viewersCandidatesQueue[callerName]);
await this.mcs.addIceCandidate(endpoint, candidate);
} catch (err) {
Logger.error("[screenshare] Viewer ICE candidate could not be added to media controller.", err);
}
@ -94,19 +94,22 @@ module.exports = class Screenshare extends EventEmitter {
}
flushCandidatesQueue (mediaId, queue) {
Logger.debug("[screenshare] flushCandidatesQueue", queue);
if (mediaId) {
try {
while(queue.length) {
let candidate = queue.shift();
return new Promise((resolve, reject) => {
Logger.debug("[screenshare] flushCandidatesQueue", queue);
if (mediaId) {
let iceProcedures = queue.map((candidate) => {
this.mcs.addIceCandidate(mediaId, candidate);
}
} catch (err) {
Logger.error("[screenshare] ICE candidate could not be added to media controller.", err);
});
return Promise.all(iceProcedures).then(() => {
queue = [];
resolve();
}).catch((err) => {
Logger.error("[screenshare] ICE candidate could not be added to media controller.", err);
reject();
});
}
} else {
Logger.error("[screenshare] No mediaId");
}
});
}
mediaStateRtp (event) {
@ -236,7 +239,7 @@ module.exports = class Screenshare extends EventEmitter {
this._presenterEndpoint = retSource.sessionId;
sharedScreens[this._voiceBridge] = this._presenterEndpoint;
let presenterSdpAnswer = retSource.answer;
this.flushCandidatesQueue(this._presenterEndpoint, this._presenterCandidatesQueue);
await this.flushCandidatesQueue(this._presenterEndpoint, this._presenterCandidatesQueue);
this.mcs.on('MediaEvent' + this._presenterEndpoint, (event) => {
this.mediaStateWebRtc(event, this._id)
@ -290,7 +293,7 @@ module.exports = class Screenshare extends EventEmitter {
this._viewersEndpoint[callerName] = retSource.sessionId;
sdpAnswer = retSource.answer;
this.flushCandidatesQueue(this._viewersEndpoint[callerName], this._viewersCandidatesQueue[callerName]);
await this.flushCandidatesQueue(this._viewersEndpoint[callerName], this._viewersCandidatesQueue[callerName]);
this.mcs.on('MediaEvent' + this._viewersEndpoint[callerName], (event) => {
this.mediaStateWebRtc(event, connectionId);