您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

JingleSession.js 6.8KB

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