Permalink
Browse files

ref(XMPPEvents): move some PC related events to RTC

Moves part of the XMPP events which are clearly
related to the PeerConnection to RTCEvents.
  • Loading branch information...
paweldomas committed Jan 9, 2017
1 parent 91d0d6b commit 7c561bc9827ceb468eac0d540d3941dec3535103
View
@@ -3,7 +3,7 @@
var logger = require("jitsi-meet-logger").getLogger(__filename);
import RTC from "./modules/RTC/RTC";
import * as MediaType from "./service/RTC/MediaType";
var XMPPEvents = require("./service/xmpp/XMPPEvents");
var RTCEvents = require("./service/RTC/RTCEvents");
var EventEmitter = require("events");
import * as JitsiConferenceErrors from "./JitsiConferenceErrors";
import * as JitsiConferenceEvents from "./JitsiConferenceEvents";
@@ -472,7 +472,7 @@ JitsiConference.prototype.onTrackRemoved = function (track) {
track.muteHandler);
track.removeEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
track.audioLevelHandler);
this.room.removeListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
this.rtc.removeListener(RTCEvents.SENDRECV_STREAMS_CHANGED,
track.ssrcHandler);
// send event for stopping screen sharing
@@ -520,11 +520,12 @@ JitsiConference.prototype.replaceTrack = function (oldTrack, newTrack) {
newTrack.ssrcHandler = function (conference, ssrcMap) {
if (ssrcMap[this.getMSID()]) {
this._setSSRC(ssrcMap[this.getMSID()]);
conference.room.removeListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
conference.rtc.removeListener(
RTCEvents.SENDRECV_STREAMS_CHANGED,
this.ssrcHandler);
}
}.bind(newTrack, this);
this.room.addListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
this.rtc.addListener(RTCEvents.SENDRECV_STREAMS_CHANGED,
newTrack.ssrcHandler);
}
// Now replace the stream at the lower levels
@@ -978,7 +979,7 @@ function (jingleSession, jingleOffer, now) {
label: crossRegion
});
try {
jingleSession.initialize(false /* initiator */,this.room);
jingleSession.initialize(false /* initiator */, this.room, this.rtc);
} catch (error) {
GlobalOnErrorHandler.callErrorHandler(error);
}
@@ -1086,8 +1087,8 @@ JitsiConference.prototype.onCallEnded
localTrack._setSSRC(null);
// Bind the handler to fetch new SSRC, it will un register itself once
// it reads the values
self.room.addListener(
XMPPEvents.SENDRECV_STREAMS_CHANGED, localTrack.ssrcHandler);
self.rtc.addListener(
RTCEvents.SENDRECV_STREAMS_CHANGED, localTrack.ssrcHandler);
});
};
@@ -43,41 +43,6 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function () {
conference.rtc.closeAllDataChannels();
});
chatRoom.addListener(XMPPEvents.REMOTE_TRACK_ADDED,
function (data) {
var track = conference.rtc.createRemoteTrack(data);
if (track) {
conference.onTrackAdded(track);
}
}
);
chatRoom.addListener(XMPPEvents.REMOTE_TRACK_REMOVED,
function (streamId, trackId) {
conference.getParticipants().forEach(function(participant) {
var tracks = participant.getTracks();
for(var i = 0; i < tracks.length; i++) {
if(tracks[i]
&& tracks[i].getStreamId() == streamId
&& tracks[i].getTrackId() == trackId) {
var track = participant._tracks.splice(i, 1)[0];
conference.rtc.removeRemoteTrack(
participant.getId(), track.getType());
conference.eventEmitter.emit(
JitsiConferenceEvents.TRACK_REMOVED, track);
if(conference.transcriber){
conference.transcriber.removeTrack(track);
}
return;
}
}
});
}
);
chatRoom.addListener(XMPPEvents.AUDIO_MUTED_BY_FOCUS,
function (value) {
// set isMutedByFocus when setAudioMute Promise ends
@@ -413,31 +378,11 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function () {
});
if(conference.statistics) {
// FIXME ICE related events should end up in RTCEvents eventually
chatRoom.addListener(XMPPEvents.CONNECTION_ICE_FAILED,
function (pc) {
conference.statistics.sendIceConnectionFailedEvent(pc);
});
chatRoom.addListener(XMPPEvents.CREATE_OFFER_FAILED,
function (e, pc) {
conference.statistics.sendCreateOfferFailed(e, pc);
});
chatRoom.addListener(XMPPEvents.CREATE_ANSWER_FAILED,
function (e, pc) {
conference.statistics.sendCreateAnswerFailed(e, pc);
});
chatRoom.addListener(XMPPEvents.SET_LOCAL_DESCRIPTION_FAILED,
function (e, pc) {
conference.statistics.sendSetLocalDescFailed(e, pc);
});
chatRoom.addListener(XMPPEvents.SET_REMOTE_DESCRIPTION_FAILED,
function (e, pc) {
conference.statistics.sendSetRemoteDescFailed(e, pc);
});
chatRoom.addListener(XMPPEvents.ADD_ICE_CANDIDATE_FAILED,
function (e, pc) {
conference.statistics.sendAddIceCandidateFailed(e, pc);
@@ -449,12 +394,51 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function () {
* Setups event listeners related to conference.rtc
*/
JitsiConferenceEventManager.prototype.setupRTCListeners = function () {
var conference = this.conference;
const conference = this.conference;
const rtc = conference.rtc;
this.rtcForwarder = new EventEmitterForwarder(conference.rtc,
this.conference.eventEmitter);
this.rtcForwarder
= new EventEmitterForwarder(rtc, this.conference.eventEmitter);
conference.rtc.addListener(RTCEvents.DOMINANT_SPEAKER_CHANGED,
// FIXME REMOTE_TRACK_ADDED could come with JitsiRemoteTrack instance
rtc.addListener(RTCEvents.REMOTE_TRACK_ADDED,
function (data) {
const track = rtc.createRemoteTrack(data);
if (track) {
conference.onTrackAdded(track);
}
}
);
rtc.addListener(RTCEvents.REMOTE_TRACK_REMOVED,
function (streamId, trackId) {
conference.getParticipants().forEach(function(participant) {
const tracks = participant.getTracks();
for(let i = 0; i < tracks.length; i++) {
if(tracks[i]
&& tracks[i].getStreamId() == streamId
&& tracks[i].getTrackId() == trackId) {
const track = participant._tracks.splice(i, 1)[0];
// FIXME this can be done in RTC directly,
// before firing the event
rtc.removeRemoteTrack(
participant.getId(), track.getType());
conference.eventEmitter.emit(
JitsiConferenceEvents.TRACK_REMOVED, track);
if(conference.transcriber){
conference.transcriber.removeTrack(track);
}
return;
}
}
});
}
);
rtc.addListener(RTCEvents.DOMINANT_SPEAKER_CHANGED,
function (id) {
if(conference.lastDominantSpeaker !== id && conference.room) {
conference.lastDominantSpeaker = id;
@@ -467,7 +451,7 @@ JitsiConferenceEventManager.prototype.setupRTCListeners = function () {
}
});
conference.rtc.addListener(RTCEvents.DATA_CHANNEL_OPEN, function () {
rtc.addListener(RTCEvents.DATA_CHANNEL_OPEN, function () {
var now = window.performance.now();
logger.log("(TIME) data channel opened ", now);
conference.room.connectionTimes["data.channel.opened"] = now;
@@ -481,12 +465,12 @@ JitsiConferenceEventManager.prototype.setupRTCListeners = function () {
this.rtcForwarder.forward(RTCEvents.LASTN_ENDPOINT_CHANGED,
JitsiConferenceEvents.LAST_N_ENDPOINTS_CHANGED);
conference.rtc.addListener(RTCEvents.AVAILABLE_DEVICES_CHANGED,
rtc.addListener(RTCEvents.AVAILABLE_DEVICES_CHANGED,
function (devices) {
conference.room.updateDeviceAvailability(devices);
});
conference.rtc.addListener(RTCEvents.ENDPOINT_MESSAGE_RECEIVED,
rtc.addListener(RTCEvents.ENDPOINT_MESSAGE_RECEIVED,
function (from, payload) {
const participant = conference.getParticipantById(from);
if (participant) {
@@ -499,6 +483,33 @@ JitsiConferenceEventManager.prototype.setupRTCListeners = function () {
"for not existing participant: " + from, payload);
}
});
if(conference.statistics) {
rtc.addListener(RTCEvents.CONNECTION_ICE_FAILED,
function (pc) {
conference.statistics.sendIceConnectionFailedEvent(pc);
});
rtc.addListener(RTCEvents.CREATE_ANSWER_FAILED,
function (e, pc) {
conference.statistics.sendCreateAnswerFailed(e, pc);
});
rtc.addListener(RTCEvents.CREATE_OFFER_FAILED,
function (e, pc) {
conference.statistics.sendCreateOfferFailed(e, pc);
});
rtc.addListener(RTCEvents.SET_LOCAL_DESCRIPTION_FAILED,
function (e, pc) {
conference.statistics.sendSetLocalDescFailed(e, pc);
});
rtc.addListener(RTCEvents.SET_REMOTE_DESCRIPTION_FAILED,
function (e, pc) {
conference.statistics.sendSetRemoteDescFailed(e, pc);
});
}
};
/**
View
@@ -9,6 +9,7 @@ import * as JitsiTrackErrors from "../../JitsiTrackErrors";
var DataChannels = require("./DataChannels");
var JitsiRemoteTrack = require("./JitsiRemoteTrack.js");
var MediaType = require("../../service/RTC/MediaType");
var TraceablePeerConnection = require("./TraceablePeerConnection");
var VideoType = require("../../service/RTC/VideoType");
var GlobalOnErrorHandler = require("../util/GlobalOnErrorHandler");
import Listenable from "../util/Listenable";
@@ -197,6 +198,20 @@ export default class RTC extends Listenable {
return RTCUtils.getDeviceAvailability();
}
/**
* Creates new <tt>TraceablePeerConnection</tt>
* @param iceConfig an object describing the ICE config like defined in
* the WebRTC specification.
* @param {Object} options the config options
* @param {boolean} options.disableSimulcast <tt>true</tt> to disable
* Simulcast.
* @return {TraceablePeerConnection}
*/
createPeerConnection (iceConfig, options) {
return new TraceablePeerConnection(
this, iceConfig, RTC.getPCConstraints(), options);
}
addLocalTrack (track) {
if (!track)
throw new Error('track must not be null nor undefined');
@@ -6,7 +6,7 @@ const logger = getLogger(__filename);
import SdpConsistency from "../xmpp/SdpConsistency.js";
import RtxModifier from "../xmpp/RtxModifier.js";
var RTCBrowserType = require("./RTCBrowserType.js");
var XMPPEvents = require("../../service/xmpp/XMPPEvents");
var RTCEvents = require("../../service/RTC/RTCEvents");
var transform = require('sdp-transform');
var SDP = require("../xmpp/SDP");
var SDPUtil = require("../xmpp/SDPUtil");
@@ -16,6 +16,7 @@ var SIMULCAST_LAYERS = 3;
/**
* Creates new instance of 'TraceablePeerConnection'.
*
* @param {RTC} rtc the instance of <tt>RTC</tt> service
* @param {object} ice_config WebRTC 'PeerConnection' ICE config
* @param {object} constraints WebRTC 'PeerConnection' constraints
* @param {object} options <tt>TracablePeerConnection</tt> config options.
@@ -24,14 +25,18 @@ var SIMULCAST_LAYERS = 3;
* @param {boolean} options.disableRtx if set to 'true' will disable the RTX
* @param {boolean} options.preferH264 if set to 'true' H264 will be preferred
* over other video codecs.
* @param {EventEmitter} eventEmitter the emitter which wil be used by the new
* instance to emit events.
*
* @constructor
*/
function TraceablePeerConnection(ice_config,
constraints, options, eventEmitter) {
function TraceablePeerConnection(rtc, ice_config,
constraints, options) {
var self = this;
/**
* The parent instance of RTC service which created this
* <tt>TracablePeerConnection</tt>.
* @type {RTC}
*/
this.rtc = rtc;
this.options = options;
var RTCPeerConnectionType = null;
if (RTCBrowserType.isFirefox()) {
@@ -56,8 +61,12 @@ function TraceablePeerConnection(ice_config,
this.simulcast = new Simulcast({numOfLayers: SIMULCAST_LAYERS,
explodeRemoteSimulcast: false});
this.sdpConsistency = new SdpConsistency();
/**
* TracablePeerConnection uses RTC's eventEmitter
* @type {EventEmitter}
*/
this.eventEmitter = rtc.eventEmitter;
this.rtxModifier = new RtxModifier();
this.eventEmitter = eventEmitter;
// override as desired
this.trace = function (what, info) {
@@ -403,7 +412,8 @@ TraceablePeerConnection.prototype.setLocalDescription
},
function (err) {
self.trace('setLocalDescriptionOnFailure', err);
self.eventEmitter.emit(XMPPEvents.SET_LOCAL_DESCRIPTION_FAILED,
self.eventEmitter.emit(
RTCEvents.SET_LOCAL_DESCRIPTION_FAILED,
err, self.peerconnection);
failureCallback(err);
}
@@ -448,7 +458,7 @@ TraceablePeerConnection.prototype.setRemoteDescription
},
function (err) {
self.trace('setRemoteDescriptionOnFailure', err);
self.eventEmitter.emit(XMPPEvents.SET_REMOTE_DESCRIPTION_FAILED,
self.eventEmitter.emit(RTCEvents.SET_REMOTE_DESCRIPTION_FAILED,
err, self.peerconnection);
failureCallback(err);
}
@@ -593,7 +603,7 @@ TraceablePeerConnection.prototype.createAnswer
_fixAnswerRFC4145Setup(remoteDescription, localDescription);
answer.sdp = localDescription.raw;
this.eventEmitter.emit(XMPPEvents.SENDRECV_STREAMS_CHANGED,
this.eventEmitter.emit(RTCEvents.SENDRECV_STREAMS_CHANGED,
extractSSRCMap(answer));
successCallback(answer);
@@ -606,7 +616,7 @@ TraceablePeerConnection.prototype.createAnswer
},
(err) => {
this.trace('createAnswerOnFailure', err);
this.eventEmitter.emit(XMPPEvents.CREATE_ANSWER_FAILED, err,
this.eventEmitter.emit(RTCEvents.CREATE_ANSWER_FAILED, err,
this.peerconnection);
failureCallback(err);
},
@@ -56,14 +56,21 @@ function JingleSession(me, sid, peerjid, connection,
* @type {JingleSessionState}
*/
this.state = null;
/**
* The RTC service instance
* @type {RTC|null}
*/
this.rtc = null;
}
/**
* Prepares this object to initiate a session.
* @param isInitiator whether we will be the Jingle initiator.
* @param room <tt>ChatRoom<tt> for the conference associated with this session
* @param {RTC} rtc the RTC service instance
*/
JingleSession.prototype.initialize = function(isInitiator, room) {
JingleSession.prototype.initialize = function(isInitiator, room, rtc) {
if (this.state !== null) {
var errmsg
= 'attempt to initiate on session ' + this.sid + 'in state '
@@ -72,6 +79,7 @@ JingleSession.prototype.initialize = function(isInitiator, room) {
throw new Error(errmsg);
}
this.room = room;
this.rtc = rtc;
this.state = JingleSessionState.PENDING;
this.initiator = isInitiator ? this.me : this.peerjid;
this.responder = !isInitiator ? this.me : this.peerjid;
Oops, something went wrong.

0 comments on commit 7c561bc

Please sign in to comment.