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