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

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