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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. /**
  91. * Adds the ICE candidates found in the 'contents' array as remote
  92. * candidates?
  93. * Note: currently only used on transport-info
  94. */
  95. // eslint-disable-next-line no-unused-vars, no-empty-function
  96. addIceCandidates(contents) { }
  97. /**
  98. * Returns current state of this <tt>JingleSession</tt> instance.
  99. * @returns {JingleSessionState} the current state of this session instance.
  100. */
  101. getState() {
  102. return this.state;
  103. }
  104. /**
  105. * Handles an 'add-source' event.
  106. *
  107. * @param contents an array of Jingle 'content' elements.
  108. */
  109. // eslint-disable-next-line no-unused-vars, no-empty-function
  110. addSources(contents) { }
  111. /**
  112. * Handles a 'remove-source' event.
  113. *
  114. * @param contents an array of Jingle 'content' elements.
  115. */
  116. // eslint-disable-next-line no-unused-vars, no-empty-function
  117. removeSources(contents) { }
  118. /**
  119. * Terminates this Jingle session by sending session-terminate
  120. * @param reason XMPP Jingle error condition
  121. * @param text some meaningful error message
  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. */
  127. // eslint-disable-next-line max-params, no-unused-vars, no-empty-function
  128. terminate(reason, text, success, failure) { }
  129. /**
  130. * Handles an offer from the remote peer (prepares to accept a session).
  131. * @param jingle the 'jingle' XML element.
  132. * @param success callback called when we the incoming session has been
  133. * accepted
  134. * @param failure callback called when we fail for any reason, will supply
  135. * error object with details(which is meant more to be printed to the logger
  136. * than analysed in the code, as the error is unrecoverable anyway)
  137. */
  138. // eslint-disable-next-line no-unused-vars, no-empty-function
  139. acceptOffer(jingle, success, failure) { }
  140. }