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