Update to version v1.3.0

pull/20/head
jenkinsopenvidu 2017-12-12 15:08:27 +00:00
parent f419736560
commit c5db83951d
3 changed files with 96 additions and 77 deletions

File diff suppressed because one or more lines are too long

View File

@ -6051,9 +6051,25 @@ var Session = /** @class */ (function () {
return subscriber; return subscriber;
}; };
Session.prototype.unsubscribe = function (subscriber) { Session.prototype.unsubscribe = function (subscriber) {
this.session.unsuscribe(subscriber.stream); this.session.unsubscribe(subscriber.stream);
subscriber.stream.removeVideo(); subscriber.stream.removeVideo();
}; };
Session.prototype.signal = function (signal, completionHandler) {
var signalMessage = {};
if (signal.to && signal.to.length > 0) {
var connectionIds = [];
for (var i = 0; i < signal.to.length; i++) {
connectionIds.push(signal.to[i].connectionId);
}
signalMessage['to'] = connectionIds;
}
else {
signalMessage['to'] = [];
}
signalMessage['data'] = signal.data ? signal.data : '';
signalMessage['type'] = signal.type ? signal.type : '';
this.openVidu.openVidu.sendMessage(this.sessionId, this.connection.connectionId, JSON.stringify(signalMessage));
};
return Session; return Session;
}()); }());
exports.Session = Session; exports.Session = Session;
@ -6174,8 +6190,8 @@ var Connection = /** @class */ (function () {
} }
} }
Connection.prototype.addStream = function (stream) { Connection.prototype.addStream = function (stream) {
this.streams[stream.getIdInParticipant()] = stream; this.streams[stream.streamId] = stream;
this.room.getStreams()[stream.getIdInParticipant()] = stream; this.room.getStreams()[stream.streamId] = stream;
}; };
Connection.prototype.getStreams = function () { Connection.prototype.getStreams = function () {
return this.streams; return this.streams;
@ -6209,6 +6225,7 @@ var Connection = /** @class */ (function () {
sendVideo: streamOptions.sendVideo, sendVideo: streamOptions.sendVideo,
recvAudio: (streamOptions.audioActive == undefined ? true : streamOptions.audioActive), recvAudio: (streamOptions.audioActive == undefined ? true : streamOptions.audioActive),
recvVideo: (streamOptions.videoActive == undefined ? true : streamOptions.videoActive), recvVideo: (streamOptions.videoActive == undefined ? true : streamOptions.videoActive),
typeOfVideo: streamOptions.typeOfVideo,
activeAudio: streamOptions.activeAudio, activeAudio: streamOptions.activeAudio,
activeVideo: streamOptions.activeVideo, activeVideo: streamOptions.activeVideo,
data: streamOptions.data, data: streamOptions.data,
@ -6654,7 +6671,7 @@ var SessionInternal = /** @class */ (function () {
this.ee = new EventEmitter(); this.ee = new EventEmitter();
this.streams = {}; this.streams = {};
this.participants = {}; this.participants = {};
this.participantsSpeaking = []; this.publishersSpeaking = [];
this.connected = false; this.connected = false;
this.sessionId = this.getUrlWithoutSecret(sessionId); this.sessionId = this.getUrlWithoutSecret(sessionId);
this.localParticipant = new Connection_1.Connection(this.openVidu, true, this); this.localParticipant = new Connection_1.Connection(this.openVidu, true, this);
@ -6792,14 +6809,13 @@ var SessionInternal = /** @class */ (function () {
return this.sessionId; return this.sessionId;
}; };
SessionInternal.prototype.activateUpdateMainSpeaker = function () { SessionInternal.prototype.activateUpdateMainSpeaker = function () {
var _this = this; /*setInterval(() => {
setInterval(function () { if (this.publishersSpeaking.length > 0) {
if (_this.participantsSpeaking.length > 0) { this.ee.emitEvent('publisherStartSpeaking', [{
_this.ee.emitEvent('update-main-speaker', [{ participantId: this.publishersSpeaking[this.publishersSpeaking.length - 1]
participantId: _this.participantsSpeaking[_this.participantsSpeaking.length - 1]
}]); }]);
} }
}, this.updateSpeakerInterval); }, this.updateSpeakerInterval);*/
}; };
SessionInternal.prototype.getLocalParticipant = function () { SessionInternal.prototype.getLocalParticipant = function () {
return this.localParticipant; return this.localParticipant;
@ -6822,16 +6838,16 @@ var SessionInternal = /** @class */ (function () {
SessionInternal.prototype.subscribe = function (stream) { SessionInternal.prototype.subscribe = function (stream) {
stream.subscribe(); stream.subscribe();
}; };
SessionInternal.prototype.unsuscribe = function (stream) { SessionInternal.prototype.unsubscribe = function (stream) {
console.info("Unsubscribing from " + stream.getId()); console.info("Unsubscribing from " + stream.streamId);
this.openVidu.sendRequest('unsubscribeFromVideo', { this.openVidu.sendRequest('unsubscribeFromVideo', {
sender: stream.getId() sender: stream.streamId
}, function (error, response) { }, function (error, response) {
if (error) { if (error) {
console.error("Error unsubscribing from Subscriber", error); console.error("Error unsubscribing from Subscriber", error);
} }
else { else {
console.info("Unsubscribed correctly from " + stream.getId()); console.info("Unsubscribed correctly from " + stream.streamId);
} }
}); });
}; };
@ -6929,20 +6945,17 @@ var SessionInternal = /** @class */ (function () {
}; };
; ;
SessionInternal.prototype.onNewMessage = function (msg) { SessionInternal.prototype.onNewMessage = function (msg) {
console.info("New message: " + JSON.stringify(msg)); console.info("New signal: " + JSON.stringify(msg));
var room = msg.room; this.ee.emitEvent('signal', [{
var user = msg.user; data: msg.data,
var message = msg.message; from: this.participants[msg.from],
if (user !== undefined) { type: msg.type
this.ee.emitEvent('newMessage', [{ }]);
room: room, this.ee.emitEvent('signal:' + msg.type, [{
user: user, data: msg.data,
message: message from: this.participants[msg.from],
type: msg.type
}]); }]);
}
else {
console.warn("User undefined in new message:", msg);
}
}; };
SessionInternal.prototype.recvIceCandidate = function (msg) { SessionInternal.prototype.recvIceCandidate = function (msg) {
var candidate = { var candidate = {
@ -7059,7 +7072,7 @@ var SessionInternal = /** @class */ (function () {
}); });
} }
else { else {
this.unsuscribe(stream); this.unsubscribe(stream);
} }
}; };
SessionInternal.prototype.unpublish = function (stream) { SessionInternal.prototype.unpublish = function (stream) {
@ -7087,18 +7100,24 @@ var SessionInternal = /** @class */ (function () {
return this.streams; return this.streams;
}; };
SessionInternal.prototype.addParticipantSpeaking = function (participantId) { SessionInternal.prototype.addParticipantSpeaking = function (participantId) {
this.participantsSpeaking.push(participantId); this.publishersSpeaking.push(participantId);
this.ee.emitEvent('publisherStartSpeaking', [{
participantId: participantId
}]);
}; };
SessionInternal.prototype.removeParticipantSpeaking = function (participantId) { SessionInternal.prototype.removeParticipantSpeaking = function (participantId) {
var pos = -1; var pos = -1;
for (var i = 0; i < this.participantsSpeaking.length; i++) { for (var i = 0; i < this.publishersSpeaking.length; i++) {
if (this.participantsSpeaking[i] == participantId) { if (this.publishersSpeaking[i] == participantId) {
pos = i; pos = i;
break; break;
} }
} }
if (pos != -1) { if (pos != -1) {
this.participantsSpeaking.splice(pos, 1); this.publishersSpeaking.splice(pos, 1);
this.ee.emitEvent('publisherStopSpeaking', [{
participantId: participantId
}]);
} }
}; };
SessionInternal.prototype.stringClientMetadata = function (metadata) { SessionInternal.prototype.stringClientMetadata = function (metadata) {
@ -7174,7 +7193,7 @@ var Stream = /** @class */ (function () {
_this.videoSrcObject = srcEvent.srcObject; _this.videoSrcObject = srcEvent.srcObject;
if (_this.video) if (_this.video)
_this.video.srcObject = srcEvent.srcObject; _this.video.srcObject = srcEvent.srcObject;
console.debug("Video srcObject [" + srcEvent.srcObject + "] added to stream [" + _this.getId() + "]"); console.debug("Video srcObject [" + srcEvent.srcObject + "] added to stream [" + _this.streamId + "]");
}); });
} }
Stream.prototype.emitSrcEvent = function (wrstream) { Stream.prototype.emitSrcEvent = function (wrstream) {
@ -7237,7 +7256,7 @@ var Stream = /** @class */ (function () {
return this.localMirrored; return this.localMirrored;
}; };
Stream.prototype.getChannelName = function () { Stream.prototype.getChannelName = function () {
return this.getId() + '_' + this.chanId++; return this.streamId + '_' + this.chanId++;
}; };
Stream.prototype.isDataChannelEnabled = function () { Stream.prototype.isDataChannelEnabled = function () {
return this.dataChannel; return this.dataChannel;
@ -7280,7 +7299,7 @@ var Stream = /** @class */ (function () {
}; };
Stream.prototype.showSpinner = function (spinnerParentId) { Stream.prototype.showSpinner = function (spinnerParentId) {
var progress = document.createElement('div'); var progress = document.createElement('div');
progress.id = 'progress-' + this.getId(); progress.id = 'progress-' + this.streamId;
progress.style.background = "center transparent url('img/spinner.gif') no-repeat"; progress.style.background = "center transparent url('img/spinner.gif') no-repeat";
var spinnerParent = document.getElementById(spinnerParentId); var spinnerParent = document.getElementById(spinnerParentId);
if (spinnerParent) { if (spinnerParent) {
@ -7288,13 +7307,13 @@ var Stream = /** @class */ (function () {
} }
}; };
Stream.prototype.hideSpinner = function (spinnerId) { Stream.prototype.hideSpinner = function (spinnerId) {
spinnerId = (spinnerId === undefined) ? this.getId() : spinnerId; spinnerId = (spinnerId === undefined) ? this.streamId : spinnerId;
hide('progress-' + spinnerId); hide('progress-' + spinnerId);
}; };
Stream.prototype.playOnlyVideo = function (parentElement, thumbnailId) { Stream.prototype.playOnlyVideo = function (parentElement, thumbnailId) {
var _this = this; var _this = this;
this.video = document.createElement('video'); this.video = document.createElement('video');
this.video.id = (this.local ? 'local-' : 'remote-') + 'video-' + this.getId(); this.video.id = (this.local ? 'local-' : 'remote-') + 'video-' + this.streamId;
this.video.autoplay = true; this.video.autoplay = true;
this.video.controls = false; this.video.controls = false;
this.video.srcObject = this.videoSrcObject; this.video.srcObject = this.videoSrcObject;
@ -7305,14 +7324,14 @@ var Stream = /** @class */ (function () {
if (this.local && !this.displayMyRemote()) { if (this.local && !this.displayMyRemote()) {
this.video.muted = true; this.video.muted = true;
this.video.oncanplay = function () { this.video.oncanplay = function () {
console.info("Local 'Stream' with id [" + _this.getId() + "] video is now playing"); console.info("Local 'Stream' with id [" + _this.streamId + "] video is now playing");
_this.ee.emitEvent('video-is-playing', [{ _this.ee.emitEvent('video-is-playing', [{
element: _this.video element: _this.video
}]); }]);
}; };
} }
else { else {
this.video.title = this.getId(); this.video.title = this.streamId;
} }
if (typeof parentElement === "string") { if (typeof parentElement === "string") {
this.parentId = parentElement; this.parentId = parentElement;
@ -7335,7 +7354,7 @@ var Stream = /** @class */ (function () {
Stream.prototype.playThumbnail = function (thumbnailId) { Stream.prototype.playThumbnail = function (thumbnailId) {
var container = document.createElement('div'); var container = document.createElement('div');
container.className = "participant"; container.className = "participant";
container.id = this.getId(); container.id = this.streamId;
var thumbnail = document.getElementById(thumbnailId); var thumbnail = document.getElementById(thumbnailId);
if (thumbnail) { if (thumbnail) {
thumbnail.appendChild(container); thumbnail.appendChild(container);
@ -7343,26 +7362,20 @@ var Stream = /** @class */ (function () {
this.elements.push(container); this.elements.push(container);
var name = document.createElement('div'); var name = document.createElement('div');
container.appendChild(name); container.appendChild(name);
var userName = this.getId().replace('_webcam', ''); var userName = this.streamId.replace('_webcam', '');
if (userName.length >= 16) { if (userName.length >= 16) {
userName = userName.substring(0, 16) + "..."; userName = userName.substring(0, 16) + "...";
} }
name.appendChild(document.createTextNode(userName)); name.appendChild(document.createTextNode(userName));
name.id = "name-" + this.getId(); name.id = "name-" + this.streamId;
name.className = "name"; name.className = "name";
name.title = this.getId(); name.title = this.streamId;
this.showSpinner(thumbnailId); this.showSpinner(thumbnailId);
return this.playOnlyVideo(container, thumbnailId); return this.playOnlyVideo(container, thumbnailId);
}; };
Stream.prototype.getIdInParticipant = function () {
return this.id;
};
Stream.prototype.getParticipant = function () { Stream.prototype.getParticipant = function () {
return this.connection; return this.connection;
}; };
Stream.prototype.getId = function () {
return this.connection.connectionId + "_" + this.id;
};
Stream.prototype.getRTCPeerConnection = function () { Stream.prototype.getRTCPeerConnection = function () {
return this.getWebRtcPeer().peerConnection; return this.getWebRtcPeer().peerConnection;
}; };
@ -7457,12 +7470,13 @@ var Stream = /** @class */ (function () {
+ JSON.stringify(error)); + JSON.stringify(error));
} }
console.debug("Sending SDP offer to publish as " console.debug("Sending SDP offer to publish as "
+ this.getId(), sdpOfferParam); + this.streamId, sdpOfferParam);
this.openVidu.sendRequest("publishVideo", { this.openVidu.sendRequest("publishVideo", {
sdpOffer: sdpOfferParam, sdpOffer: sdpOfferParam,
doLoopback: this.displayMyRemote() || false, doLoopback: this.displayMyRemote() || false,
audioActive: this.sendAudio, audioActive: this.sendAudio,
videoActive: this.sendVideo videoActive: this.sendVideo,
typeOfVideo: ((this.sendVideo) ? ((this.isScreenRequested) ? 'SCREEN' : 'CAMERA') : '')
}, function (error, response) { }, function (error, response) {
if (error) { if (error) {
console.error("Error on publishVideo: " + JSON.stringify(error)); console.error("Error on publishVideo: " + JSON.stringify(error));
@ -7480,9 +7494,9 @@ var Stream = /** @class */ (function () {
+ JSON.stringify(error)); + JSON.stringify(error));
} }
console.debug("Sending SDP offer to subscribe to " console.debug("Sending SDP offer to subscribe to "
+ this.getId(), sdpOfferParam); + this.streamId, sdpOfferParam);
this.openVidu.sendRequest("receiveVideoFrom", { this.openVidu.sendRequest("receiveVideoFrom", {
sender: this.getId(), sender: this.streamId,
sdpOffer: sdpOfferParam sdpOffer: sdpOfferParam
}, function (error, response) { }, function (error, response) {
if (error) { if (error) {
@ -7550,7 +7564,7 @@ var Stream = /** @class */ (function () {
}); });
} }
console.debug("Waiting for SDP offer to be generated (" console.debug("Waiting for SDP offer to be generated ("
+ (this.local ? "local" : "remote") + " 'Stream': " + this.getId() + ")"); + (this.local ? "local" : "remote") + " 'Stream': " + this.streamId + ")");
}; };
Stream.prototype.publish = function () { Stream.prototype.publish = function () {
var _this = this; var _this = this;
@ -7579,8 +7593,8 @@ var Stream = /** @class */ (function () {
type: 'answer', type: 'answer',
sdp: sdpAnswer sdp: sdpAnswer
}); });
console.debug(this.getId() + ": set peer connection with recvd SDP answer", sdpAnswer); console.debug(this.streamId + ": set peer connection with recvd SDP answer", sdpAnswer);
var participantId = this.getId(); var participantId = this.streamId;
var pc = this.wp.peerConnection; var pc = this.wp.peerConnection;
pc.setRemoteDescription(answer, function () { pc.setRemoteDescription(answer, function () {
// Avoids to subscribe to your own stream remotely // Avoids to subscribe to your own stream remotely
@ -7593,15 +7607,17 @@ var Stream = /** @class */ (function () {
if (_this.wrStream.getAudioTracks()[0] != null) { if (_this.wrStream.getAudioTracks()[0] != null) {
_this.speechEvent = kurentoUtils.WebRtcPeer.hark(_this.wrStream, { threshold: _this.room.thresholdSpeaker }); _this.speechEvent = kurentoUtils.WebRtcPeer.hark(_this.wrStream, { threshold: _this.room.thresholdSpeaker });
_this.speechEvent.on('speaking', function () { _this.speechEvent.on('speaking', function () {
_this.room.addParticipantSpeaking(participantId); //this.room.addParticipantSpeaking(participantId);
_this.room.emitEvent('stream-speaking', [{ _this.room.emitEvent('publisherStartSpeaking', [{
participantId: participantId connection: _this.connection,
streamId: _this.streamId
}]); }]);
}); });
_this.speechEvent.on('stopped_speaking', function () { _this.speechEvent.on('stopped_speaking', function () {
_this.room.removeParticipantSpeaking(participantId); //this.room.removeParticipantSpeaking(participantId);
_this.room.emitEvent('stream-stopped-speaking', [{ _this.room.emitEvent('publisherStopSpeaking', [{
participantId: participantId connection: _this.connection,
streamId: _this.streamId
}]); }]);
}); });
} }
@ -7612,19 +7628,19 @@ var Stream = /** @class */ (function () {
video.srcObject = _this.wrStream; video.srcObject = _this.wrStream;
video.oncanplay = function () { video.oncanplay = function () {
if (_this.local && _this.displayMyRemote()) { if (_this.local && _this.displayMyRemote()) {
console.info("Your own remote 'Stream' with id [" + _this.getId() + "] video is now playing"); console.info("Your own remote 'Stream' with id [" + _this.streamId + "] video is now playing");
_this.ee.emitEvent('remote-video-is-playing', [{ _this.ee.emitEvent('remote-video-is-playing', [{
element: video element: video
}]); }]);
} }
else if (!_this.local && !_this.displayMyRemote()) { else if (!_this.local && !_this.displayMyRemote()) {
console.info("Remote 'Stream' with id [" + _this.getId() + "] video is now playing"); console.info("Remote 'Stream' with id [" + _this.streamId + "] video is now playing");
_this.ee.emitEvent('video-is-playing', [{ _this.ee.emitEvent('video-is-playing', [{
element: video element: video
}]); }]);
} }
//show(thumbnailId); //show(thumbnailId);
//this.hideSpinner(this.getId()); //this.hideSpinner(this.streamId);
}; };
}; };
for (var _i = 0, _a = _this.videoElements; _i < _a.length; _i++) { for (var _i = 0, _a = _this.videoElements; _i < _a.length; _i++) {
@ -7636,7 +7652,7 @@ var Stream = /** @class */ (function () {
}]); }]);
} }
}, function (error) { }, function (error) {
console.error(_this.getId() + ": Error setting SDP to the peer connection: " console.error(_this.streamId + ": Error setting SDP to the peer connection: "
+ JSON.stringify(error)); + JSON.stringify(error));
}); });
}; };
@ -7657,7 +7673,7 @@ var Stream = /** @class */ (function () {
if (this.speechEvent) { if (this.speechEvent) {
this.speechEvent.stop(); this.speechEvent.stop();
} }
console.info(this.getId() + ": Stream '" + this.id + "' unpublished"); console.info(this.streamId + ": Stream '" + this.streamId + "' unpublished");
}; };
Stream.prototype.dispose = function () { Stream.prototype.dispose = function () {
function disposeElement(element) { function disposeElement(element) {
@ -7667,7 +7683,7 @@ var Stream = /** @class */ (function () {
} }
this.elements.forEach(function (e) { return disposeElement(e); }); this.elements.forEach(function (e) { return disposeElement(e); });
//this.videoElements.forEach(ve => disposeElement(ve.video)); //this.videoElements.forEach(ve => disposeElement(ve.video));
disposeElement("progress-" + this.getId()); disposeElement("progress-" + this.streamId);
if (this.wp) { if (this.wp) {
this.wp.dispose(); this.wp.dispose();
} }
@ -7684,14 +7700,14 @@ var Stream = /** @class */ (function () {
if (this.speechEvent) { if (this.speechEvent) {
this.speechEvent.stop(); this.speechEvent.stop();
} }
console.info((this.local ? "Local " : "Remote ") + "'Stream' with id [" + this.getId() + "]' has been succesfully disposed"); console.info((this.local ? "Local " : "Remote ") + "'Stream' with id [" + this.streamId + "]' has been succesfully disposed");
}; };
Stream.prototype.configureOptions = function (options) { Stream.prototype.configureOptions = function (options) {
if (options.id) { if (options.id) {
this.id = options.id; this.streamId = options.id;
} }
else { else {
this.id = "webcam"; this.streamId = "WEBCAM";
} }
this.connection = options.connection; this.connection = options.connection;
this.recvVideo = options.recvVideo || false; this.recvVideo = options.recvVideo || false;
@ -7702,13 +7718,16 @@ var Stream = /** @class */ (function () {
this.activeVideo = options.activeVideo; this.activeVideo = options.activeVideo;
this.dataChannel = options.data || false; this.dataChannel = options.data || false;
this.mediaConstraints = options.mediaConstraints; this.mediaConstraints = options.mediaConstraints;
this.hasAudio = ((this.recvAudio || this.sendAudio) != undefined) ? (this.recvAudio || this.sendAudio) : false;
this.hasVideo = ((this.recvVideo || this.sendVideo) != undefined) ? (this.recvVideo || this.sendVideo) : false;
this.typeOfVideo = options.typeOfVideo;
}; };
Stream.prototype.configureScreenOptions = function (options) { Stream.prototype.configureScreenOptions = function (options) {
if (options.id) { if (options.id) {
this.id = options.id; this.streamId = options.id;
} }
else { else {
this.id = "screen"; this.streamId = "SCREEN";
} }
this.recvVideo = options.recvVideo || false; this.recvVideo = options.recvVideo || false;
this.recvAudio = options.recvAudio || false; this.recvAudio = options.recvAudio || false;

File diff suppressed because one or more lines are too long