Merge pull request #426 from isymchych/move-dtmf

Add DTMF support to JS API
This commit is contained in:
hristoterezov 2015-12-09 13:59:18 +11:00
commit a68eaeefe6
16 changed files with 1603 additions and 1103 deletions

10
.editorconfig Normal file
View File

@ -0,0 +1,10 @@
# http://editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
max_line_length = 80
trim_trailing_whitespace = true

View File

@ -1,4 +1,5 @@
/* global Strophe, $ */
/* jshint -W101 */
var logger = require("jitsi-meet-logger").getLogger(__filename);
var RTC = require("./modules/RTC/RTC");
var XMPPEvents = require("./service/xmpp/XMPPEvents");
@ -7,6 +8,7 @@ var EventEmitter = require("events");
var JitsiConferenceEvents = require("./JitsiConferenceEvents");
var JitsiParticipant = require("./JitsiParticipant");
var Statistics = require("./modules/statistics/statistics");
var JitsiDTMFManager = require('./modules/DTMF/JitsiDTMFManager');
var JitsiTrackEvents = require("./JitsiTrackEvents");
/**
@ -18,7 +20,6 @@ var JitsiTrackEvents = require("./JitsiTrackEvents");
* @param options.connection the JitsiConnection object for this JitsiConference.
* @constructor
*/
function JitsiConference(options) {
if(!options.name || options.name.toLowerCase() !== options.name) {
logger.error("Invalid conference name (no conference name passed or it"
@ -37,6 +38,8 @@ function JitsiConference(options) {
setupListeners(this);
this.participants = {};
this.lastActiveSpeaker = null;
this.dtmfManager = null;
this.somebodySupportsDTMF = false;
}
/**
@ -46,7 +49,7 @@ function JitsiConference(options) {
JitsiConference.prototype.join = function (password) {
if(this.room)
this.room.join(password, this.connection.tokenPassword);
}
};
/**
* Leaves the conference.
@ -55,14 +58,17 @@ JitsiConference.prototype.leave = function () {
if(this.xmpp)
this.xmpp.leaveRoom(this.room.roomjid);
this.room = null;
}
};
/**
* Returns the local tracks.
*/
JitsiConference.prototype.getLocalTracks = function () {
if(this.rtc)
if (this.rtc) {
return this.rtc.localStreams;
} else {
return [];
}
};
@ -77,7 +83,7 @@ JitsiConference.prototype.getLocalTracks = function () {
JitsiConference.prototype.on = function (eventId, handler) {
if(this.eventEmitter)
this.eventEmitter.on(eventId, handler);
}
};
/**
* Removes event listener
@ -89,7 +95,7 @@ JitsiConference.prototype.on = function (eventId, handler) {
JitsiConference.prototype.off = function (eventId, handler) {
if(this.eventEmitter)
this.eventEmitter.removeListener(eventId, handler);
}
};
// Common aliases for event emitter
JitsiConference.prototype.addEventListener = JitsiConference.prototype.on;
@ -104,7 +110,7 @@ JitsiConference.prototype.removeEventListener = JitsiConference.prototype.off;
JitsiConference.prototype.addCommandListener = function (command, handler) {
if(this.room)
this.room.addPresenceListener(command, handler);
}
};
/**
* Removes command listener
@ -113,7 +119,7 @@ JitsiConference.prototype.removeEventListener = JitsiConference.prototype.off;
JitsiConference.prototype.removeCommandListener = function (command) {
if(this.room)
this.room.removePresenceListener(command);
}
};
/**
* Sends text message to the other participants in the conference
@ -122,7 +128,7 @@ JitsiConference.prototype.removeEventListener = JitsiConference.prototype.off;
JitsiConference.prototype.sendTextMessage = function (message) {
if(this.room)
this.room.sendMessage(message);
}
};
/**
* Send presence command.
@ -134,7 +140,7 @@ JitsiConference.prototype.sendCommand = function (name, values) {
this.room.addToPresence(name, values);
this.room.sendPresence();
}
}
};
/**
* Send presence command one time.
@ -144,7 +150,7 @@ JitsiConference.prototype.sendCommand = function (name, values) {
JitsiConference.prototype.sendCommandOnce = function (name, values) {
this.sendCommand(name, values);
this.removeCommand(name);
}
};
/**
* Send presence command.
@ -155,7 +161,7 @@ JitsiConference.prototype.sendCommandOnce = function (name, values) {
JitsiConference.prototype.removeCommand = function (name) {
if(this.room)
this.room.removeFromPresence(name);
}
};
/**
* Sets the display name for this conference.
@ -166,7 +172,7 @@ JitsiConference.prototype.setDisplayName = function(name) {
this.room.addToPresence("nick", {attributes: {xmlns: 'http://jabber.org/protocol/nick'}, value: name});
this.room.sendPresence();
}
}
};
/**
* Adds JitsiLocalTrack object to the conference.
@ -180,20 +186,18 @@ JitsiConference.prototype.addTrack = function (track) {
var audioLevelHandler = this._fireAudioLevelChangeEvent.bind(this);
track.addEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED, muteHandler);
track.addEventListener(JitsiTrackEvents.TRACK_STOPPED, stopHandler);
track.addEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
audioLevelHandler);
this.addEventListener(JitsiConferenceEvents.TRACK_REMOVED, function (track) {
track.removeEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED,
muteHandler);
track.removeEventListener(JitsiTrackEvents.TRACK_STOPPED,
stopHandler);
track.removeEventListener(
JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED, audioLevelHandler);
})
track.addEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED, audioLevelHandler);
this.addEventListener(JitsiConferenceEvents.TRACK_REMOVED, function (someTrack) {
if (someTrack !== track) {
return;
}
track.removeEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED, muteHandler);
track.removeEventListener(JitsiTrackEvents.TRACK_STOPPED, stopHandler);
track.removeEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED, audioLevelHandler);
});
this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
}.bind(this));
}
};
/**
* Fires TRACK_AUDIO_LEVEL_CHANGED change conference event.
@ -203,7 +207,7 @@ JitsiConference.prototype._fireAudioLevelChangeEvent = function (audioLevel) {
this.eventEmitter.emit(
JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
this.myUserId(), audioLevel);
}
};
/**
* Fires TRACK_MUTE_CHANGED change conference event.
@ -222,7 +226,23 @@ JitsiConference.prototype.removeTrack = function (track) {
this.rtc.removeLocalStream(track);
this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
}.bind(this));
}
};
/**
* Get role of the local user.
* @returns {string} user role: 'moderator' or 'none'
*/
JitsiConference.prototype.getRole = function () {
return this.room.role;
};
/**
* Check if local user is moderator.
* @returns {boolean} true if local user is moderator, false otherwise.
*/
JitsiConference.prototype.isModerator = function () {
return this.room.isModerator();
};
/**
* Elects the participant with the given id to be the selected participant or the speaker.
@ -232,41 +252,138 @@ JitsiConference.prototype.selectParticipant = function(participantId) {
if (this.rtc) {
this.rtc.selectedEndpoint(participantId);
}
}
};
/**
*
* @param id the identifier of the participant
*/
JitsiConference.prototype.pinParticipant = function(participantId) {
if(this.rtc)
if (this.rtc) {
this.rtc.pinEndpoint(participantId);
}
}
};
/**
* Returns the list of participants for this conference.
* @return Object a list of participant identifiers containing all conference participants.
* @return Array<JitsiParticipant> a list of participant identifiers containing all conference participants.
*/
JitsiConference.prototype.getParticipants = function() {
return this.participants;
}
return Object.keys(this.participants).map(function (key) {
return this.participants[key];
}, this);
};
/**
* @returns {JitsiParticipant} the participant in this conference with the specified id (or
* null if there isn't one).
* undefined if there isn't one).
* @param id the id of the participant.
*/
JitsiConference.prototype.getParticipantById = function(id) {
if(this.participants)
return this.participants[id];
return null;
}
return this.participants[id];
};
JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {
if(this.eventEmitter)
this.eventEmitter.emit(JitsiConferenceEvents.USER_JOINED, Strophe.getResourceFromJid(jid));
// this.participants[jid] = new JitsiParticipant();
}
var id = Strophe.getResourceFromJid(jid);
var participant = new JitsiParticipant(id, this, nick);
this.eventEmitter.emit(JitsiConferenceEvents.USER_JOINED, id);
this.participants[id] = participant;
this.connection.xmpp.connection.disco.info(
jid, "" /* node */, function(iq) {
participant._supportsDTMF = $(iq).find('>query>feature[var="urn:xmpp:jingle:dtmf:0"]').length > 0;
this.updateDTMFSupport();
}.bind(this)
);
};
JitsiConference.prototype.onMemberLeft = function (jid) {
var id = Strophe.getResourceFromJid(jid);
delete this.participants[id];
this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id);
};
JitsiConference.prototype.onUserRoleChanged = function (jid, role) {
var id = Strophe.getResourceFromJid(jid);
var participant = this.getParticipantById(id);
if (!participant) {
return;
}
participant._role = role;
this.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, id, role);
};
JitsiConference.prototype.onDisplayNameChanged = function (jid, displayName) {
var id = Strophe.getResourceFromJid(jid);
var participant = this.getParticipantById(id);
if (!participant) {
return;
}
participant._displayName = displayName;
this.eventEmitter.emit(JitsiConferenceEvents.DISPLAY_NAME_CHANGED, id, displayName);
};
JitsiConference.prototype.onTrackAdded = function (track) {
var id = track.getParticipantId();
var participant = this.getParticipantById(id);
if (!participant) {
return;
}
// add track to JitsiParticipant
participant._tracks.push(track);
var emitter = this.eventEmitter;
track.addEventListener(
JitsiTrackEvents.TRACK_STOPPED,
function () {
// remove track from JitsiParticipant
var pos = participant._tracks.indexOf(track);
if (pos > -1) {
participant._tracks.splice(pos, 1);
}
emitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
}
);
track.addEventListener(
JitsiTrackEvents.TRACK_MUTE_CHANGED,
function () {
emitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
}
);
track.addEventListener(
JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
function (audioLevel) {
emitter.emit(JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED, id, audioLevel);
}
);
this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
};
JitsiConference.prototype.updateDTMFSupport = function () {
var somebodySupportsDTMF = false;
var participants = this.getParticipants();
// check if at least 1 participant supports DTMF
for (var i = 0; i < participants.length; i += 1) {
if (participants[i].supportsDTMF()) {
somebodySupportsDTMF = true;
break;
}
}
if (somebodySupportsDTMF !== this.somebodySupportsDTMF) {
this.somebodySupportsDTMF = somebodySupportsDTMF;
this.eventEmitter.emit(JitsiConferenceEvents.DTMF_SUPPORT_CHANGED, somebodySupportsDTMF);
}
};
/**
* Allows to check if there is at least one user in the conference
* that supports DTMF.
* @returns {boolean} true if somebody supports DTMF, false otherwise
*/
JitsiConference.prototype.isDTMFSupported = function () {
return this.somebodySupportsDTMF;
};
/**
* Returns the local user's ID
@ -274,7 +391,28 @@ JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {
*/
JitsiConference.prototype.myUserId = function () {
return (this.room && this.room.myroomjid)? Strophe.getResourceFromJid(this.room.myroomjid) : null;
}
};
JitsiConference.prototype.sendTones = function (tones, duration, pause) {
if (!this.dtmfManager) {
var connection = this.connection.xmpp.connection.jingle.activecall.peerconnection;
if (!connection) {
logger.warn("cannot sendTones: no conneciton");
return;
}
var tracks = this.getLocalTracks().filter(function (track) {
return track.isAudioTrack();
});
if (!tracks.length) {
logger.warn("cannot sendTones: no local audio stream");
return;
}
this.dtmfManager = new JitsiDTMFManager(tracks[0], connection);
}
this.dtmfManager.sendTones(tones, duration, pause);
};
/**
* Setups the listeners needed for the conference.
@ -290,27 +428,9 @@ function setupListeners(conference) {
conference.room.addListener(XMPPEvents.REMOTE_STREAM_RECEIVED,
function (data, sid, thessrc) {
var track = conference.rtc.createRemoteStream(data, sid, thessrc);
if(!track)
return;
conference.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED,
track);
track.addEventListener(JitsiTrackEvents.TRACK_STOPPED,
function () {
conference.eventEmitter.emit(
JitsiConferenceEvents.TRACK_REMOVED, track);
});
track.addEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED,
function () {
conference.eventEmitter.emit(
JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
});
var userId = track.getParitcipantId();
track.addEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
function (audioLevel) {
conference.eventEmitter.emit(
JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
userId, audioLevel);
});
if (track) {
conference.onTrackAdded(track);
}
}
);
@ -322,30 +442,24 @@ function setupListeners(conference) {
// conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_LEFT);
// });
conference.room.addListener(XMPPEvents.MUC_MEMBER_JOINED,
conference.onMemberJoined.bind(conference));
conference.room.addListener(XMPPEvents.MUC_MEMBER_LEFT,function (jid) {
conference.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT,
Strophe.getResourceFromJid(jid));
conference.room.addListener(XMPPEvents.MUC_MEMBER_JOINED, conference.onMemberJoined.bind(conference));
conference.room.addListener(XMPPEvents.MUC_MEMBER_LEFT, conference.onMemberLeft.bind(conference));
conference.room.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, conference.onDisplayNameChanged.bind(conference));
conference.room.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, function (role) {
conference.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, conference.myUserId(), role);
});
conference.room.addListener(XMPPEvents.MUC_ROLE_CHANGED, conference.onUserRoleChanged.bind(conference));
conference.room.addListener(XMPPEvents.DISPLAY_NAME_CHANGED,
function (from, displayName) {
conference.eventEmitter.emit(
JitsiConferenceEvents.DISPLAY_NAME_CHANGED,
Strophe.getResourceFromJid(from), displayName);
});
conference.room.addListener(XMPPEvents.CONNECTION_INTERRUPTED,
function () {
conference.eventEmitter.emit(
JitsiConferenceEvents.CONNECTION_INTERRUPTED);
});
conference.room.addListener(XMPPEvents.CONNECTION_INTERRUPTED, function () {
conference.eventEmitter.emit(JitsiConferenceEvents.CONNECTION_INTERRUPTED);
});
conference.room.addListener(XMPPEvents.CONNECTION_RESTORED, function () {
conference.eventEmitter.emit(JitsiConferenceEvents.CONNECTION_RESTORED);
});
conference.room.addListener(XMPPEvents.CONFERENCE_SETUP_FAILED, function() {
conference.room.addListener(XMPPEvents.CONFERENCE_SETUP_FAILED, function () {
conference.eventEmitter.emit(JitsiConferenceEvents.SETUP_FAILED);
});

View File

@ -23,6 +23,10 @@ var JitsiConferenceEvents = {
* A user has left the conference.
*/
USER_LEFT: "conference.userLeft",
/**
* User role changed.
*/
USER_ROLE_CHANGED: "conference.roleChanged",
/**
* New text message was received.
*/
@ -75,7 +79,11 @@ var JitsiConferenceEvents = {
/**
* Indicates that conference has been left.
*/
CONFERENCE_LEFT: "conference.left"
CONFERENCE_LEFT: "conference.left",
/**
* Indicates that DTMF support changed.
*/
DTMF_SUPPORT_CHANGED: "conference.dtmfSupportChanged"
};
module.exports = JitsiConferenceEvents;

View File

@ -5,6 +5,9 @@ function JitsiParticipant(id, conference, displayName){
this._id = id;
this._conference = conference;
this._displayName = displayName;
this._supportsDTMF = false;
this._tracks = [];
this._role = 'none';
}
/**
@ -12,34 +15,35 @@ function JitsiParticipant(id, conference, displayName){
*/
JitsiParticipant.prototype.getConference = function() {
return this._conference;
}
};
/**
* @returns {Array.<JitsiTrack>} The list of media tracks for this participant.
*/
JitsiParticipant.prototype.getTracks = function() {
}
return this._tracks;
};
/**
* @returns {String} The ID (i.e. JID) of this participant.
*/
JitsiParticipant.prototype.getId = function() {
return this._id;
}
};
/**
* @returns {String} The human-readable display name of this participant.
*/
JitsiParticipant.prototype.getDisplayName = function() {
return this._displayName;
}
};
/**
* @returns {Boolean} Whether this participant is a moderator or not.
*/
JitsiParticipant.prototype.isModerator = function() {
}
return this._role === 'moderator';
};
// Gets a link to an etherpad instance advertised by the participant?
//JitsiParticipant.prototype.getEtherpad = function() {
@ -51,15 +55,19 @@ JitsiParticipant.prototype.isModerator = function() {
* @returns {Boolean} Whether this participant has muted their audio.
*/
JitsiParticipant.prototype.isAudioMuted = function() {
}
return this.getTracks().reduce(function (track, isAudioMuted) {
return isAudioMuted && (track.isVideoTrack() || track.isMuted());
}, true);
};
/*
* @returns {Boolean} Whether this participant has muted their video.
*/
JitsiParticipant.prototype.isVideoMuted = function() {
}
return this.getTracks().reduce(function (track, isVideoMuted) {
return isVideoMuted && (track.isAudioTrack() || track.isMuted());
}, true);
};
/*
* @returns {???} The latest statistics reported by this participant (i.e. info used to populate the GSM bars)
@ -67,70 +75,67 @@ JitsiParticipant.prototype.isVideoMuted = function() {
*/
JitsiParticipant.prototype.getLatestStats = function() {
}
};
/**
* @returns {String} The role of this participant.
*/
JitsiParticipant.prototype.getRole = function() {
}
return this._role;
};
/*
* @returns {Boolean} Whether this participant is the conference focus (i.e. jicofo).
*/
JitsiParticipant.prototype.isFocus = function() {
}
};
/*
* @returns {Boolean} Whether this participant is a conference recorder (i.e. jirecon).
*/
JitsiParticipant.prototype.isRecorder = function() {
}
};
/*
* @returns {Boolean} Whether this participant is a SIP gateway (i.e. jigasi).
*/
JitsiParticipant.prototype.isSipGateway = function() {
}
/**
* @returns {String} The ID for this participant's avatar.
*/
JitsiParticipant.prototype.getAvatarId = function() {
}
};
/**
* @returns {Boolean} Whether this participant is currently sharing their screen.
*/
JitsiParticipant.prototype.isScreenSharing = function() {
}
};
/**
* @returns {String} The user agent of this participant (i.e. browser userAgent string).
*/
JitsiParticipant.prototype.getUserAgent = function() {
}
};
/**
* Kicks the participant from the conference (requires certain privileges).
*/
JitsiParticipant.prototype.kick = function() {
}
};
/**
* Asks this participant to mute themselves.
*/
JitsiParticipant.prototype.askToMute = function() {
}
};
JitsiParticipant.prototype.supportsDTMF = function () {
return this._supportsDTMF;
};
module.exports = JitsiParticipant();
module.exports = JitsiParticipant;

View File

@ -77,6 +77,8 @@ JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
- IN_LAST_N_CHANGED - passes boolean property that shows whether the local user is included in last n set of any other user or not. (parameters - boolean)
- CONFERENCE_JOINED - notifies the local user that he joined the conference successfully. (no parameters)
- CONFERENCE_LEFT - notifies the local user that he left the conference successfully. (no parameters)
- DTMF_SUPPORT_CHANGED - notifies if at least one user supports DTMF. (parameters - supports(boolean))
- USER_ROLE_CHANGED - notifies that role of some user changed. (parameters - id(string), role(string))
2. connection
- CONNECTION_FAILED - indicates that the server connection failed.
@ -213,35 +215,49 @@ The object represents a conference. We have the following methods to control the
17. addTrack(track) - Adds JitsiLocalTrack object to the conference.
- track - the JitsiLocalTrack
17. removeTrack(track) - Removes JitsiLocalTrack object to the conference.
18. removeTrack(track) - Removes JitsiLocalTrack object to the conference.
- track - the JitsiLocalTrack
19. isDTMFSupported() - Check if at least one user supports DTMF.
20. getRole() - returns string with the local user role ("moderator" or "none")
21. isModerator() - checks if local user has "moderator" role
JitsiTrack
======
The object represents single track - video or audio. They can be remote tracks ( from the other participants in the call) or local tracks (from the devices of the local participant).
We have the following methods for controling the tracks:
1.getType() - returns string with the type of the track( "video" for the video tracks and "audio" for the audio tracks)
1. getType() - returns string with the type of the track( "video" for the video tracks and "audio" for the audio tracks)
2.mute() - mutes the track.
2. mute() - mutes the track.
Note: This method is implemented only for the local tracks.
Note: This method is implemented only for the local tracks.
3.unmute() - unmutes the track.
3. unmute() - unmutes the track.
Note: This method is implemented only for the local tracks.
Note: This method is implemented only for the local tracks.
4. isMuted() - check if track is muted
4. attach(container) - attaches the track to the given container.
5. attach(container) - attaches the track to the given container.
5. detach(container) - removes the track from the container.
6. detach(container) - removes the track from the container.
6. stop() - stop sending the track to the other participants in the conference.
7. stop() - stop sending the track to the other participants in the conference.
Note: This method is implemented only for the local tracks.
Note: This method is implemented only for the local tracks.
7. getId() - returns unique string for the track.
8. getId() - returns unique string for the track.
9. getParticipantId() - returns id(string) of the track owner
Note: This method is implemented only for the remote tracks.
Getting Started

View File

@ -50,7 +50,7 @@ function onLocalTracks(tracks)
function onRemoteTrack(track) {
if(track.isLocal())
return;
var participant = track.getParitcipantId();
var participant = track.getParticipantId();
if(!remoteTracks[participant])
remoteTracks[participant] = [];
var idx = remoteTracks[participant].push(track);

File diff suppressed because it is too large Load Diff

View File

@ -1,47 +0,0 @@
/* global APP */
/**
* A module for sending DTMF tones.
*/
var DTMFSender;
var initDtmfSender = function() {
// TODO: This needs to reset this if the peerconnection changes
// (e.g. the call is re-made)
if (DTMFSender)
return;
var localAudio = APP.RTC.localAudio;
if (localAudio && localAudio.getTracks().length > 0)
{
var peerconnection
= APP.xmpp.getConnection().jingle.activecall.peerconnection;
if (peerconnection) {
DTMFSender =
peerconnection.peerconnection
.createDTMFSender(localAudio.getTracks()[0]);
console.log("Initialized DTMFSender");
}
else {
console.log("Failed to initialize DTMFSender: no PeerConnection.");
}
}
else {
console.log("Failed to initialize DTMFSender: no audio track.");
}
};
var DTMF = {
sendTones: function (tones, duration, pause) {
if (!DTMFSender)
initDtmfSender();
if (DTMFSender){
DTMFSender.insertDTMF(tones,
(duration || 200),
(pause || 200));
}
}
};
module.exports = DTMF;

View File

@ -0,0 +1,15 @@
var logger = require("jitsi-meet-logger").getLogger(__filename);
function JitsiDTMFManager (localAudio, peerConnection) {
var tracks = localAudio._getTracks();
if (!tracks.length) {
throw new Error("Failed to initialize DTMFSender: no audio track.");
}
this.dtmfSender = peerConnection.peerconnection.createDTMFSender(tracks[0]);
logger.debug("Initialized DTMFSender");
}
JitsiDTMFManager.prototype.sendTones = function (tones, duration, pause) {
this.dtmfSender.insertDTMF(tones, (duration || 200), (pause || 200));
};

View File

@ -53,7 +53,7 @@ JitsiRemoteTrack.prototype.isMuted = function () {
* Returns the participant id which owns the track.
* @returns {string} the id of the participants.
*/
JitsiRemoteTrack.prototype.getParitcipantId = function() {
JitsiRemoteTrack.prototype.getParticipantId = function() {
return Strophe.getResourceFromJid(this.peerjid);
};

View File

@ -96,6 +96,20 @@ JitsiTrack.prototype.getType = function() {
return this.type;
};
/**
* Check if this is audiotrack.
*/
JitsiTrack.prototype.isAudioTrack = function () {
return this.getType() === JitsiTrack.AUDIO;
};
/**
* Check if this is videotrack.
*/
JitsiTrack.prototype.isVideoTrack = function () {
return this.getType() === JitsiTrack.VIDEO;
};
/**
* Returns the RTCMediaStream from the browser (?).
*/

View File

@ -1,4 +1,9 @@
/* global config, require, attachMediaStream, getUserMedia */
/* global config, require, attachMediaStream, getUserMedia,
RTCPeerConnection, RTCSessionDescription, RTCIceCandidate, MediaStreamTrack,
mozRTCPeerConnection, mozRTCSessionDescription, mozRTCIceCandidate,
webkitRTCPeerConnection, webkitMediaStream, webkitURL
*/
/* jshint -W101 */
var logger = require("jitsi-meet-logger").getLogger(__filename);
var RTCBrowserType = require("./RTCBrowserType");
@ -15,7 +20,7 @@ var eventEmitter = new EventEmitter();
var devices = {
audio: true,
video: true
}
};
var rtcReady = false;
@ -197,7 +202,7 @@ function onReady (options, GUM) {
rtcReady = true;
eventEmitter.emit(RTCEvents.RTC_READY, true);
screenObtainer.init(eventEmitter, options, GUM);
};
}
/**
* Apply function with arguments if function exists.
@ -325,8 +330,8 @@ function enumerateDevicesThroughMediaStreamTrack (callback) {
}
function obtainDevices(options) {
if(!options.devices || options.devices.length === 0) {
return options.successCallback(streams);
if (!options.devices || options.devices.length === 0) {
return options.successCallback(options.streams);
}
var device = options.devices.splice(0, 1);
@ -366,8 +371,8 @@ function handleLocalStream(streams, resolution) {
var videoTracks = audioVideo.getVideoTracks();
if(videoTracks.length) {
videoStream = new webkitMediaStream();
for (i = 0; i < videoTracks.length; i++) {
videoStream.addTrack(videoTracks[i]);
for (var j = 0; j < videoTracks.length; j++) {
videoStream.addTrack(videoTracks[j]);
}
}
}
@ -506,7 +511,7 @@ var RTCUtils = {
//AdapterJS.WebRTCPlugin.setLogLevel(
// AdapterJS.WebRTCPlugin.PLUGIN_LOG_LEVELS.VERBOSE);
var self = this;
AdapterJS.webRTCReady(function (isPlugin) {
self.peerconnection = RTCPeerConnection;
@ -564,7 +569,7 @@ var RTCUtils = {
// Call onReady() if Temasys plugin is not used
if (!RTCBrowserType.isTemasysPluginUsed()) {
onReady(options, self.getUserMediaWithConstraints);
onReady(options, this.getUserMediaWithConstraints);
resolve();
}
}.bind(this));
@ -583,9 +588,8 @@ var RTCUtils = {
**/
getUserMediaWithConstraints: function ( um, success_callback, failure_callback, options) {
options = options || {};
resolution = options.resolution;
var constraints = getConstraints(
um, options);
var resolution = options.resolution;
var constraints = getConstraints(um, options);
logger.info("Get media constraints", constraints);
@ -642,12 +646,12 @@ var RTCUtils = {
RTCBrowserType.isTemasysPluginUsed()) {
var GUM = function (device, s, e) {
this.getUserMediaWithConstraints(device, s, e, options);
}
};
var deviceGUM = {
"audio": GUM.bind(self, ["audio"]),
"video": GUM.bind(self, ["video"]),
"desktop": screenObtainer.obtainStream
}
};
// With FF/IE we can't split the stream into audio and video because FF
// doesn't support media stream constructors. So, we need to get the
// audio stream separately from the video stream using two distinct GUM
@ -658,13 +662,14 @@ var RTCUtils = {
// the successCallback method.
obtainDevices({
devices: options.devices,
streams: [],
successCallback: successCallback,
errorCallback: reject,
deviceGUM: deviceGUM
});
} else {
var hasDesktop = false;
if(hasDesktop = options.devices.indexOf("desktop") !== -1) {
var hasDesktop = options.devices.indexOf('desktop') > -1;
if (hasDesktop) {
options.devices.splice(options.devices.indexOf("desktop"), 1);
}
options.resolution = options.resolution || '360';

View File

@ -1,128 +0,0 @@
/* global APP, require, $ */
/**
* This module is meant to (eventually) contain and manage all information
* about members/participants of the conference, so that other modules don't
* have to do it on their own, and so that other modules can access members'
* information from a single place.
*
* Currently this module only manages information about the support of jingle
* DTMF of the members. Other fields, as well as accessor methods are meant to
* be added as needed.
*/
var XMPPEvents = require("../../service/xmpp/XMPPEvents");
var Events = require("../../service/members/Events");
var EventEmitter = require("events");
var eventEmitter = new EventEmitter();
/**
* The actual container.
*/
var members = {};
/**
* There is at least one member that supports DTMF (i.e. is jigasi).
*/
var atLeastOneDtmf = false;
function registerListeners() {
APP.xmpp.addListener(XMPPEvents.MUC_MEMBER_JOINED, onMucMemberJoined);
APP.xmpp.addListener(XMPPEvents.MUC_MEMBER_LEFT, onMucMemberLeft);
}
/**
* Handles a new member joining the MUC.
*/
function onMucMemberJoined(jid, id, displayName) {
var member = {
displayName: displayName
};
APP.xmpp.getConnection().disco.info(
jid, "" /* node */, function(iq) { onDiscoInfoReceived(jid, iq); });
members[jid] = member;
}
/**
* Handles a member leaving the MUC.
*/
function onMucMemberLeft(jid) {
delete members[jid];
updateAtLeastOneDtmf();
}
/**
* Handles the reception of a disco#info packet from a particular JID.
* @param jid the JID sending the packet.
* @param iq the packet.
*/
function onDiscoInfoReceived(jid, iq) {
if (!members[jid])
return;
var supportsDtmf
= $(iq).find('>query>feature[var="urn:xmpp:jingle:dtmf:0"]').length > 0;
updateDtmf(jid, supportsDtmf);
}
/**
* Updates the 'supportsDtmf' field for a member.
* @param jid the jid of the member.
* @param newValue the new value for the 'supportsDtmf' field.
*/
function updateDtmf(jid, newValue) {
var oldValue = members[jid].supportsDtmf;
members[jid].supportsDtmf = newValue;
if (newValue != oldValue) {
updateAtLeastOneDtmf();
}
}
/**
* Checks each member's 'supportsDtmf' field and updates
* 'atLastOneSupportsDtmf'.
*/
function updateAtLeastOneDtmf() {
var newAtLeastOneDtmf = false;
for (var key in members) {
if (typeof members[key].supportsDtmf !== 'undefined'
&& members[key].supportsDtmf) {
newAtLeastOneDtmf= true;
break;
}
}
if (atLeastOneDtmf != newAtLeastOneDtmf) {
atLeastOneDtmf = newAtLeastOneDtmf;
eventEmitter.emit(Events.DTMF_SUPPORT_CHANGED, atLeastOneDtmf);
}
}
/**
* Exported interface.
*/
var Members = {
start: function() {
registerListeners();
},
addListener: function(type, listener) {
eventEmitter.on(type, listener);
},
removeListener: function (type, listener) {
eventEmitter.removeListener(type, listener);
},
size: function () {
return Object.keys(members).length;
},
getMembers: function () {
return members;
}
};
module.exports = Members;

View File

@ -1,4 +1,5 @@
/* global Strophe, $, $pres, $iq, $msg */
/* jshint -W101,-W069 */
var logger = require("jitsi-meet-logger").getLogger(__filename);
var XMPPEvents = require("../../service/xmpp/XMPPEvents");
var Moderator = require("./moderator");
@ -9,23 +10,24 @@ var parser = {
var self = this;
$(packet).children().each(function (index) {
var tagName = $(this).prop("tagName");
var node = {}
node["tagName"] = tagName;
var node = {
tagName: tagName
};
node.attributes = {};
$($(this)[0].attributes).each(function( index, attr ) {
node.attributes[ attr.name ] = attr.value;
} );
});
var text = Strophe.getText($(this)[0]);
if(text)
if (text) {
node.value = text;
}
node.children = [];
nodes.push(node);
self.packet2JSON($(this), node.children);
})
});
},
JSON2packet: function (nodes, packet) {
for(var i = 0; i < nodes.length; i++)
{
for(var i = 0; i < nodes.length; i++) {
var node = nodes[i];
if(!node || node === null){
continue;
@ -67,7 +69,7 @@ function ChatRoom(connection, jid, password, XMPP, options) {
this.presMap = {};
this.presHandlers = {};
this.joined = false;
this.role = null;
this.role = 'none';
this.focusMucJid = null;
this.bridgeIsDown = false;
this.options = options || {};
@ -104,7 +106,7 @@ ChatRoom.prototype.updateDeviceAvailability = function (devices) {
}
]
});
}
};
ChatRoom.prototype.join = function (password, tokenPassword) {
if(password)
@ -206,7 +208,7 @@ ChatRoom.prototype.onPresence = function (pres) {
member.jid = tmp.attr('jid');
member.isFocus = false;
if (member.jid
&& member.jid.indexOf(this.moderator.getFocusUserJid() + "/") == 0) {
&& member.jid.indexOf(this.moderator.getFocusUserJid() + "/") === 0) {
member.isFocus = true;
}
@ -255,8 +257,7 @@ ChatRoom.prototype.onPresence = function (pres) {
if (this.role !== member.role) {
this.role = member.role;
this.eventEmitter.emit(XMPPEvents.LOCAL_ROLE_CHANGED,
member, this.isModerator());
this.eventEmitter.emit(XMPPEvents.LOCAL_ROLE_CHANGED, this.role);
}
if (!this.joined) {
this.joined = true;
@ -279,8 +280,7 @@ ChatRoom.prototype.onPresence = function (pres) {
// Watch role change:
if (this.members[from].role != member.role) {
this.members[from].role = member.role;
this.eventEmitter.emit(XMPPEvents.MUC_ROLE_CHANGED,
member.role, member.nick);
this.eventEmitter.emit(XMPPEvents.MUC_ROLE_CHANGED, from, member.role);
}
// store the new display name
@ -345,7 +345,7 @@ ChatRoom.prototype.onPresenceUnavailable = function (pres, from) {
this.xmpp.disposeConference(false);
this.eventEmitter.emit(XMPPEvents.MUC_DESTROYED, reason);
delete this.connection.emuc.rooms[Strophe.getBareJidFromJid(jid)];
delete this.connection.emuc.rooms[Strophe.getBareJidFromJid(from)];
return true;
}
@ -388,7 +388,7 @@ ChatRoom.prototype.onMessage = function (msg, from) {
var subject = $(msg).find('>subject');
if (subject.length) {
var subjectText = subject.text();
if (subjectText || subjectText == "") {
if (subjectText || subjectText === "") {
this.eventEmitter.emit(XMPPEvents.SUBJECT_CHANGED, subjectText);
logger.log("Subject is changed to " + subjectText);
}
@ -413,7 +413,7 @@ ChatRoom.prototype.onMessage = function (msg, from) {
this.eventEmitter.emit(XMPPEvents.MESSAGE_RECEIVED,
from, nick, txt, this.myroomjid, stamp);
}
}
};
ChatRoom.prototype.onPresenceError = function (pres, from) {
if ($(pres).find('>error[type="auth"]>not-authorized[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) {
@ -492,13 +492,13 @@ ChatRoom.prototype.removeFromPresence = function (key) {
ChatRoom.prototype.addPresenceListener = function (name, handler) {
this.presHandlers[name] = handler;
}
};
ChatRoom.prototype.removePresenceListener = function (name) {
delete this.presHandlers[name];
}
};
ChatRoom.prototype.isModerator = function (jid) {
ChatRoom.prototype.isModerator = function () {
return this.role === 'moderator';
};
@ -519,7 +519,7 @@ ChatRoom.prototype.removeStream = function (stream, callback) {
if(!this.session)
return;
this.session.removeStream(stream, callback);
}
};
ChatRoom.prototype.switchStreams = function (stream, oldStream, callback, isAudio) {
if(this.session) {
@ -541,14 +541,14 @@ ChatRoom.prototype.addStream = function (stream, callback) {
logger.warn("No conference handler or conference not started yet");
callback();
}
}
};
ChatRoom.prototype.setVideoMute = function (mute, callback, options) {
var self = this;
var localCallback = function (mute) {
self.sendVideoInfoPresence(mute);
if(callback)
callback(mute)
callback(mute);
};
if(this.session)
@ -581,7 +581,7 @@ ChatRoom.prototype.addAudioInfoToPresence = function (mute) {
{attributes:
{"audions": "http://jitsi.org/jitmeet/audio"},
value: mute.toString()});
}
};
ChatRoom.prototype.sendAudioInfoPresence = function(mute, callback) {
this.addAudioInfoToPresence(mute);
@ -598,7 +598,7 @@ ChatRoom.prototype.addVideoInfoToPresence = function (mute) {
{attributes:
{"videons": "http://jitsi.org/jitmeet/video"},
value: mute.toString()});
}
};
ChatRoom.prototype.sendVideoInfoPresence = function (mute) {
@ -631,7 +631,7 @@ ChatRoom.prototype.remoteStreamAdded = function(data, sid, thessrc) {
}
this.eventEmitter.emit(XMPPEvents.REMOTE_STREAM_RECEIVED, data, sid, thessrc);
}
};
ChatRoom.prototype.getJidBySSRC = function (ssrc) {
if (!this.session)

View File

@ -1,4 +1,3 @@
var logger = require("jitsi-meet-logger").getLogger(__filename);
var RTCBrowserType = require("../RTC/RTCBrowserType");
@ -361,4 +360,5 @@ SDPUtil = {
return line + '\r\n';
}
};
module.exports = SDPUtil;

View File

@ -1,5 +0,0 @@
var Events = {
DTMF_SUPPORT_CHANGED: "members.dtmf_support_changed"
};
module.exports = Events;