modified lib-jitsi-meet dev repo
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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