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 5.4KB

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