You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JingleSession.js 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import { getLogger } from '@jitsi/logger';
  2. import Listenable from '../util/Listenable';
  3. import * as JingleSessionState from './JingleSessionState';
  4. const logger = getLogger(__filename);
  5. /**
  6. * JingleSession provides an API to manage a single Jingle session. We will
  7. * have different implementations depending on the underlying interface used
  8. * (i.e. WebRTC and ORTC) and here we hold the code common to all of them.
  9. */
  10. export default class JingleSession extends Listenable {
  11. /* eslint-disable max-params */
  12. /**
  13. * Creates new <tt>JingleSession</tt>.
  14. * @param {string} sid the Jingle session identifier
  15. * @param {string} localJid our JID
  16. * @param {string} remoteJid the JID of the remote peer
  17. * @param {XmppConnection} connection the XMPP connection
  18. * @param {Object} mediaConstraints the media constraints object passed to the PeerConnection onCreateAnswer/Offer.
  19. * @param {Object} pcConfig The {@code RTCConfiguration} object passed to the PeerConnection's constructor.
  20. * @param {boolean} isInitiator indicates if it will be the side which initiates the session.
  21. */
  22. constructor(
  23. sid,
  24. localJid,
  25. remoteJid,
  26. connection,
  27. mediaConstraints,
  28. pcConfig,
  29. isInitiator) {
  30. super();
  31. this.sid = sid;
  32. this.localJid = localJid;
  33. this.remoteJid = remoteJid;
  34. this.connection = connection;
  35. this.mediaConstraints = mediaConstraints;
  36. this.pcConfig = pcConfig;
  37. /**
  38. * Indicates whether this instance is an initiator or an answerer of
  39. * the Jingle session.
  40. * @type {boolean}
  41. */
  42. this.isInitiator = isInitiator;
  43. /**
  44. * Whether to use dripping or not. Dripping is sending trickle
  45. * candidates not one-by-one.
  46. */
  47. this.usedrip = true;
  48. /**
  49. * When dripping is used, stores ICE candidates which are to be sent.
  50. */
  51. this.dripContainer = [];
  52. /**
  53. * The chat room instance associated with the session.
  54. * @type {ChatRoom}
  55. */
  56. this.room = null;
  57. /**
  58. * The signaling layer.
  59. * @type {SignalingLayerImpl | null}
  60. * @private
  61. */
  62. this._signalingLayer = null;
  63. /**
  64. * Jingle session state - uninitialized until {@link initialize} is
  65. * called @type {JingleSessionState}
  66. */
  67. this.state = null;
  68. /**
  69. * The RTC service instance
  70. * @type {RTC}
  71. */
  72. this.rtc = null;
  73. }
  74. /**
  75. * Returns XMPP address of this session's initiator.
  76. * @return {string}
  77. */
  78. get initiatorJid() {
  79. return this.isInitiator ? this.localJid : this.remoteJid;
  80. }
  81. /**
  82. * Returns XMPP address of this session's responder.
  83. * @return {string}
  84. */
  85. get responderJid() {
  86. return this.isInitiator ? this.remoteJid : this.localJid;
  87. }
  88. /* eslint-enable max-params */
  89. /**
  90. * Prepares this object to initiate a session.
  91. * @param {ChatRoom} room the chat room for the conference associated with
  92. * this session
  93. * @param {RTC} rtc the RTC service instance
  94. * @param {SignalingLayerImpl} signalingLayer - The signaling layer instance.
  95. * @param {object} options - the options, see implementing class's
  96. * {@link #doInitialize} description for more details.
  97. */
  98. initialize(room, rtc, signalingLayer, options) {
  99. if (this.state !== null) {
  100. const errmsg
  101. = `attempt to initiate on session ${this.sid}
  102. in state ${this.state}`;
  103. logger.error(errmsg);
  104. throw new Error(errmsg);
  105. }
  106. // TODO decouple from room
  107. this.room = room;
  108. this.rtc = rtc;
  109. this._signalingLayer = signalingLayer;
  110. this.state = JingleSessionState.PENDING;
  111. this.doInitialize(options);
  112. }
  113. /**
  114. * The implementing class finishes initialization here. Called at the end of
  115. * {@link initialize}.
  116. * @param {Object} options - The options specific to the implementing class.
  117. * @protected
  118. */
  119. doInitialize(options) { } // eslint-disable-line no-unused-vars, no-empty-function, max-len
  120. /* eslint-disable no-unused-vars, no-empty-function */
  121. /**
  122. * Adds the ICE candidates found in the 'contents' array as remote
  123. * candidates?
  124. * Note: currently only used on transport-info
  125. *
  126. * @param contents
  127. */
  128. addIceCandidates(contents) {}
  129. /* eslint-enable no-unused-vars, no-empty-function */
  130. /**
  131. * Returns current state of this <tt>JingleSession</tt> instance.
  132. * @returns {JingleSessionState} the current state of this session instance.
  133. */
  134. getState() {
  135. return this.state;
  136. }
  137. /* eslint-disable no-unused-vars, no-empty-function */
  138. /**
  139. * Handles an 'add-source' event.
  140. *
  141. * @param contents an array of Jingle 'content' elements.
  142. */
  143. addSources(contents) {}
  144. /**
  145. * Handles a 'remove-source' event.
  146. *
  147. * @param contents an array of Jingle 'content' elements.
  148. */
  149. removeSources(contents) {}
  150. /**
  151. * Terminates this Jingle session by sending session-terminate
  152. * @param success a callback called once the 'session-terminate' packet has
  153. * been acknowledged with RESULT.
  154. * @param failure a callback called when either timeout occurs or ERROR
  155. * response is received.
  156. * @param {Object} options
  157. * @param {string} [options.reason] XMPP Jingle error condition
  158. * @param {string} [options.reasonDescription] some meaningful error message
  159. * @param {boolean} [options.requestRestart=false] set to true to ask Jicofo to start a new session one this once is
  160. * terminated.
  161. * @param {boolean} [options.sendSessionTerminate=true] set to false to skip
  162. * sending session-terminate. It may not make sense to send it if the XMPP
  163. * connection has been closed already or if the remote peer has disconnected
  164. */
  165. terminate(success, failure, options) {}
  166. /**
  167. * Handles an offer from the remote peer (prepares to accept a session).
  168. * @param jingle the 'jingle' XML element.
  169. * @param success callback called when we the incoming session has been
  170. * accepted
  171. * @param failure callback called when we fail for any reason, will supply
  172. * error object with details(which is meant more to be printed to the logger
  173. * than analysed in the code, as the error is unrecoverable anyway)
  174. */
  175. acceptOffer(jingle, success, failure) {}
  176. /* eslint-enable no-unused-vars, no-empty-function */
  177. }