Permalink
Browse files

ref(JingleSession): convert to ES6 syntax

  • Loading branch information...
paweldomas committed Jan 16, 2017
1 parent 3386696 commit 67e7f8086fef6d16a38b80d36a26bd5ec8b4b45f
Showing with 127 additions and 114 deletions.
  1. +127 −114 modules/xmpp/JingleSession.js
@@ -1,148 +1,161 @@
import {getLogger} from "jitsi-meet-logger";
const logger = getLogger(__filename);
import * as JingleSessionState from "./JingleSessionState";
/*
* JingleSession provides an API to manage a single Jingle session. We will
* have different implementations depending on the underlying interface used
* (i.e. WebRTC and ORTC) and here we hold the code common to all of them.
*/
import {getLogger} from "jitsi-meet-logger";
const logger = getLogger(__filename);
import * as JingleSessionState from "./JingleSessionState";
export default class JingleSession {
function JingleSession(me, sid, peerjid, connection,
media_constraints, ice_config) {
/**
* Our JID.
* Creates new <tt>JingleSession</tt>.
* @param {string} me our JID
* @param {string} sid the Jingle session identifier
* @param {string} peerjid the JID of the remote peer
* @param {Strophe.Connection} connection the XMPP connection
* @param {Object} media_constraints the media constraints object passed to
* the PeerConnection onCreateAnswer/Offer as defined by the WebRTC.
* @param {Object} ice_config the ICE servers config object as defined by
* the WebRTC. Passed to the PeerConnection's constructor.
*/
this.me = me;
constructor(me, sid, peerjid, connection, media_constraints, ice_config) {
this.me = me;
this.sid = sid;
this.peerjid = peerjid;
this.connection = connection;
this.media_constraints = media_constraints;
this.ice_config = ice_config;
/**
* Whether to use dripping or not. Dripping is sending trickle
* candidates not one-by-one.
* Note: currently we do not support 'false'.
*/
this.usedrip = true;
/**
* When dripping is used, stores ICE candidates which are to be sent.
*/
this.drip_container = [];
/**
* The chat room instance associated with the session.
* @type {ChatRoom}
*/
this.room = null;
/**
* Jingle session state - uninitialized until {@link initialize} is
* called @type {JingleSessionState}
*/
this.state = null;
/**
* The RTC service instance
* @type {RTC|null}
*/
this.rtc = null;
}
/**
* The Jingle session identifier.
* Prepares this object to initiate a session.
* @param {boolean} isInitiator whether we will be the Jingle initiator.
* @param {ChatRoom} room the chat room for the conference associated with
* this session
* @param {RTC} rtc the RTC service instance
*/
this.sid = sid;
initialize(isInitiator, room, rtc) {
if (this.state !== null) {
const errmsg
= 'attempt to initiate on session ' + this.sid + 'in state '
+ this.state;
logger.error(errmsg);
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;
this.doInitialize();
}
/**
* the JID of the remote peer.
* The implementing class finishes initialization here. Called at the end of
* {@link initialize}.
*/
this.peerjid = peerjid;
doInitialize() {
}
/**
* The XMPP connection.
* Adds the ICE candidates found in the 'contents' array as remote
* candidates?
* Note: currently only used on transport-info
*/
this.connection = connection;
// eslint-disable-next-line no-unused-vars
addIceCandidates (contents) {
}
/**
* Whether to use dripping or not. Dripping is sending trickle candidates
* not one-by-one.
* Note: currently we do not support 'false'.
* Returns current state of this <tt>JingleSession</tt> instance.
* @returns {JingleSessionState} the current state of this session instance.
*/
this.usedrip = true;
getState () {
return this.state;
}
/**
* When dripping is used, stores ICE candidates which are to be sent.
* Handles an 'add-source' event.
*
* @param contents an array of Jingle 'content' elements.
*/
this.drip_container = [];
// Media constraints. Is this WebRTC only?
this.media_constraints = media_constraints;
// ICE servers config (RTCConfiguration?).
this.ice_config = ice_config;
// eslint-disable-next-line no-unused-vars
addSources (contents) {
// The chat room instance associated with the session.
this.room = null;
}
/**
* Jingle session state - uninitialized until {@link initialize} is called
* @type {JingleSessionState}
* Handles a 'remove-source' event.
*
* @param contents an array of Jingle 'content' elements.
*/
this.state = null;
// eslint-disable-next-line no-unused-vars
removeSources (contents) {
}
/**
* The RTC service instance
* @type {RTC|null}
* Terminates this Jingle session by sending session-terminate
* @param reason XMPP Jingle error condition
* @param text some meaningful error message
* @param success a callback called once the 'session-terminate' packet has
* been acknowledged with RESULT.
* @param failure a callback called when either timeout occurs or ERROR
* response is received.
*/
this.rtc = null;
}
// eslint-disable-next-line no-unused-vars
terminate (reason, text, success, failure) {
/**
* 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, rtc) {
if (this.state !== null) {
var errmsg
= 'attempt to initiate on session ' + this.sid + 'in state '
+ this.state;
logger.error(errmsg);
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;
this.doInitialize();
};
/**
* Finishes initialization.
*/
JingleSession.prototype.doInitialize = function() {};
/**
* Adds the ICE candidates found in the 'contents' array as remote candidates?
* Note: currently only used on transport-info
*/
// eslint-disable-next-line no-unused-vars
JingleSession.prototype.addIceCandidates = function(contents) {};
/**
* Returns current state of this <tt>JingleSession</tt> instance.
* @returns {JingleSessionState} the current state of this session instance.
*/
JingleSession.prototype.getState = function () {
return this.state;
};
/**
* Handles an 'add-source' event.
*
* @param contents an array of Jingle 'content' elements.
*/
// eslint-disable-next-line no-unused-vars
JingleSession.prototype.addSources = function(contents) {};
/**
* Handles a 'remove-source' event.
*
* @param contents an array of Jingle 'content' elements.
*/
// eslint-disable-next-line no-unused-vars
JingleSession.prototype.removeSources = function(contents) {};
/**
* Terminates this Jingle session by sending session-terminate
* @param reason XMPP Jingle error condition
* @param text some meaningful error message
* @param success a callback called once the 'session-terminate' packet has been
* acknowledged with RESULT.
* @param failure a callback called when either timeout occurs or ERROR response
* is received.
*/
// eslint-disable-next-line no-unused-vars
JingleSession.prototype.terminate = function(reason, text, success, failure) {};
/**
* Handles an offer from the remote peer (prepares to accept a session).
* @param jingle the 'jingle' XML element.
* @param success callback called when we the incoming session has been accepted
* @param failure callback called when we fail for any reason, will supply error
* object with details(which is meant more to be printed to the logger
* than analysed in the code, as the error is unrecoverable anyway)
*/
// eslint-disable-next-line no-unused-vars
JingleSession.prototype.acceptOffer = function(jingle, success, failure) {};
/**
* Handles an offer from the remote peer (prepares to accept a session).
* @param jingle the 'jingle' XML element.
* @param success callback called when we the incoming session has been
* accepted
* @param failure callback called when we fail for any reason, will supply
* error object with details(which is meant more to be printed to
* the logger than analysed in the code, as the error is
* unrecoverable anyway)
*/
// eslint-disable-next-line no-unused-vars
acceptOffer (jingle, success, failure) {
module.exports = JingleSession;
}
}

0 comments on commit 67e7f80

Please sign in to comment.