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

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