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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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, service, eventEmitter) {
  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. * The XMPP service.
  29. */
  30. this.service = service;
  31. /**
  32. * The event emitter.
  33. */
  34. this.eventEmitter = eventEmitter;
  35. /**
  36. * Whether to use dripping or not. Dripping is sending trickle candidates
  37. * not one-by-one.
  38. * Note: currently we do not support 'false'.
  39. */
  40. this.usedrip = true;
  41. /**
  42. * When dripping is used, stores ICE candidates which are to be sent.
  43. */
  44. this.drip_container = [];
  45. // Media constraints. Is this WebRTC only?
  46. this.media_constraints = media_constraints;
  47. // ICE servers config (RTCConfiguration?).
  48. this.ice_config = ice_config;
  49. // The chat room instance associated with the session.
  50. this.room = null;
  51. /**
  52. * Jingle session state - uninitialized until {@link initialize} is called
  53. * @type {JingleSessionState}
  54. */
  55. this.state = null;
  56. }
  57. /**
  58. * Prepares this object to initiate a session.
  59. * @param isInitiator whether we will be the Jingle initiator.
  60. * @param room <tt>ChatRoom<tt> for the conference associated with this session
  61. */
  62. JingleSession.prototype.initialize = function(isInitiator, room) {
  63. if (this.state !== null) {
  64. var errmsg
  65. = 'attempt to initiate on session ' + this.sid + 'in state '
  66. + this.state;
  67. logger.error(errmsg);
  68. throw new Error(errmsg);
  69. }
  70. this.room = room;
  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. * Finishes initialization.
  78. */
  79. JingleSession.prototype.doInitialize = function() {};
  80. /**
  81. * Adds the ICE candidates found in the 'contents' array as remote candidates?
  82. * Note: currently only used on transport-info
  83. */
  84. // eslint-disable-next-line no-unused-vars
  85. JingleSession.prototype.addIceCandidates = function(contents) {};
  86. /**
  87. * Returns current state of this <tt>JingleSession</tt> instance.
  88. * @returns {JingleSessionState} the current state of this session instance.
  89. */
  90. JingleSession.prototype.getState = function () {
  91. return this.state;
  92. };
  93. /**
  94. * Handles an 'add-source' event.
  95. *
  96. * @param contents an array of Jingle 'content' elements.
  97. */
  98. // eslint-disable-next-line no-unused-vars
  99. JingleSession.prototype.addSources = function(contents) {};
  100. /**
  101. * Handles a 'remove-source' event.
  102. *
  103. * @param contents an array of Jingle 'content' elements.
  104. */
  105. // eslint-disable-next-line no-unused-vars
  106. JingleSession.prototype.removeSources = function(contents) {};
  107. /**
  108. * Terminates this Jingle session by sending session-terminate
  109. * @param reason XMPP Jingle error condition
  110. * @param text some meaningful error message
  111. * @param success a callback called once the 'session-terminate' packet has been
  112. * acknowledged with RESULT.
  113. * @param failure a callback called when either timeout occurs or ERROR response
  114. * is received.
  115. */
  116. // eslint-disable-next-line no-unused-vars
  117. JingleSession.prototype.terminate = function(reason, text, success, failure) {};
  118. /**
  119. * Handles an offer from the remote peer (prepares to accept a session).
  120. * @param jingle the 'jingle' XML element.
  121. * @param success callback called when we the incoming session has been accepted
  122. * @param failure callback called when we fail for any reason, will supply error
  123. * object with details(which is meant more to be printed to the logger
  124. * than analysed in the code, as the error is unrecoverable anyway)
  125. */
  126. // eslint-disable-next-line no-unused-vars
  127. JingleSession.prototype.acceptOffer = function(jingle, success, failure) {};
  128. module.exports = JingleSession;