Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

JingleSession.js 6.5KB

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