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.3KB

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