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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * JingleSession provides an API to manage a single Jingle session. We will
  3. * have different implementations depending on the underlying interface used
  4. * (i.e. WebRTC and ORTC) and here we hold the code common to all of them.
  5. */
  6. import {getLogger} from "jitsi-meet-logger";
  7. const logger = getLogger(__filename);
  8. import * as JingleSessionState from "./JingleSessionState";
  9. function JingleSession(me, sid, peerjid, connection,
  10. media_constraints, ice_config) {
  11. /**
  12. * Our JID.
  13. */
  14. this.me = me;
  15. /**
  16. * The Jingle session identifier.
  17. */
  18. this.sid = sid;
  19. /**
  20. * the JID of the remote peer.
  21. */
  22. this.peerjid = peerjid;
  23. /**
  24. * The XMPP connection.
  25. */
  26. this.connection = connection;
  27. /**
  28. * Whether to use dripping or not. Dripping is sending trickle candidates
  29. * not one-by-one.
  30. * Note: currently we do not support 'false'.
  31. */
  32. this.usedrip = true;
  33. /**
  34. * When dripping is used, stores ICE candidates which are to be sent.
  35. */
  36. this.drip_container = [];
  37. // Media constraints. Is this WebRTC only?
  38. this.media_constraints = media_constraints;
  39. // ICE servers config (RTCConfiguration?).
  40. this.ice_config = ice_config;
  41. // The chat room instance associated with the session.
  42. this.room = null;
  43. /**
  44. * Jingle session state - uninitialized until {@link initialize} is called
  45. * @type {JingleSessionState}
  46. */
  47. this.state = null;
  48. }
  49. /**
  50. * Prepares this object to initiate a session.
  51. * @param isInitiator whether we will be the Jingle initiator.
  52. * @param room <tt>ChatRoom<tt> for the conference associated with this session
  53. */
  54. JingleSession.prototype.initialize = function(isInitiator, room) {
  55. if (this.state !== null) {
  56. var errmsg
  57. = 'attempt to initiate on session ' + this.sid + 'in state '
  58. + this.state;
  59. logger.error(errmsg);
  60. throw new Error(errmsg);
  61. }
  62. this.room = room;
  63. this.state = JingleSessionState.PENDING;
  64. this.initiator = isInitiator ? this.me : this.peerjid;
  65. this.responder = !isInitiator ? this.me : this.peerjid;
  66. this.doInitialize();
  67. };
  68. /**
  69. * Finishes initialization.
  70. */
  71. JingleSession.prototype.doInitialize = function() {};
  72. /**
  73. * Adds the ICE candidates found in the 'contents' array as remote candidates?
  74. * Note: currently only used on transport-info
  75. */
  76. // eslint-disable-next-line no-unused-vars
  77. JingleSession.prototype.addIceCandidates = function(contents) {};
  78. /**
  79. * Returns current state of this <tt>JingleSession</tt> instance.
  80. * @returns {JingleSessionState} the current state of this session instance.
  81. */
  82. JingleSession.prototype.getState = function () {
  83. return this.state;
  84. };
  85. /**
  86. * Handles an 'add-source' event.
  87. *
  88. * @param contents an array of Jingle 'content' elements.
  89. */
  90. // eslint-disable-next-line no-unused-vars
  91. JingleSession.prototype.addSources = function(contents) {};
  92. /**
  93. * Handles a 'remove-source' event.
  94. *
  95. * @param contents an array of Jingle 'content' elements.
  96. */
  97. // eslint-disable-next-line no-unused-vars
  98. JingleSession.prototype.removeSources = function(contents) {};
  99. /**
  100. * Terminates this Jingle session by sending session-terminate
  101. * @param reason XMPP Jingle error condition
  102. * @param text some meaningful error message
  103. * @param success a callback called once the 'session-terminate' packet has been
  104. * acknowledged with RESULT.
  105. * @param failure a callback called when either timeout occurs or ERROR response
  106. * is received.
  107. */
  108. // eslint-disable-next-line no-unused-vars
  109. JingleSession.prototype.terminate = function(reason, text, success, failure) {};
  110. /**
  111. * Handles an offer from the remote peer (prepares to accept a session).
  112. * @param jingle the 'jingle' XML element.
  113. * @param success callback called when we the incoming session has been accepted
  114. * @param failure callback called when we fail for any reason, will supply error
  115. * object with details(which is meant more to be printed to the logger
  116. * than analysed in the code, as the error is unrecoverable anyway)
  117. */
  118. // eslint-disable-next-line no-unused-vars
  119. JingleSession.prototype.acceptOffer = function(jingle, success, failure) {};
  120. module.exports = JingleSession;