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

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