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 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. var logger = require("jitsi-meet-logger").getLogger(__filename);
  7. function JingleSession(me, sid, peerjid, connection,
  8. media_constraints, ice_config, service, eventEmitter) {
  9. /**
  10. * Our JID.
  11. */
  12. this.me = me;
  13. /**
  14. * The Jingle session identifier.
  15. */
  16. this.sid = sid;
  17. /**
  18. * the JID of the remote peer.
  19. */
  20. this.peerjid = peerjid;
  21. /**
  22. * The XMPP connection.
  23. */
  24. this.connection = connection;
  25. /**
  26. * The XMPP service.
  27. */
  28. this.service = service;
  29. /**
  30. * The event emitter.
  31. */
  32. this.eventEmitter = eventEmitter;
  33. /**
  34. * Whether to use dripping or not. Dripping is sending trickle candidates
  35. * not one-by-one.
  36. * Note: currently we do not support 'false'.
  37. */
  38. this.usedrip = true;
  39. /**
  40. * When dripping is used, stores ICE candidates which are to be sent.
  41. */
  42. this.drip_container = [];
  43. // Media constraints. Is this WebRTC only?
  44. this.media_constraints = media_constraints;
  45. // ICE servers config (RTCConfiguration?).
  46. this.ice_config = ice_config;
  47. // The chat room instance associated with the session.
  48. this.room = null;
  49. // Jingle session state - uninitialized until 'initialize' is called
  50. this.state = null;
  51. }
  52. /**
  53. * Prepares this object to initiate a session.
  54. * @param isInitiator whether we will be the Jingle initiator.
  55. * @param room <tt>ChatRoom<tt> for the conference associated with this session
  56. */
  57. JingleSession.prototype.initialize = function(isInitiator, room) {
  58. if (this.state !== null) {
  59. var errmsg
  60. = 'attempt to initiate on session ' + this.sid + 'in state '
  61. + this.state;
  62. logger.error(errmsg);
  63. throw new Error(errmsg);
  64. }
  65. this.room = room;
  66. this.state = 'pending';
  67. this.initiator = isInitiator ? this.me : this.peerjid;
  68. this.responder = !isInitiator ? this.me : this.peerjid;
  69. this.doInitialize();
  70. };
  71. /**
  72. * Finishes initialization.
  73. */
  74. JingleSession.prototype.doInitialize = function() {};
  75. /**
  76. * Adds the ICE candidates found in the 'contents' array as remote candidates?
  77. * Note: currently only used on transport-info
  78. */
  79. JingleSession.prototype.addIceCandidates = function(contents) {};
  80. /**
  81. * Checks if this JingleSession is in 'active' state which means that the call
  82. * is in progress.
  83. * @returns {boolean} <tt>true</tt> if this JingleSession is in 'active' state
  84. * or <tt>false</tt> otherwise.
  85. */
  86. JingleSession.prototype.active = function () {
  87. return this.state === 'active';
  88. };
  89. /**
  90. * Handles an 'add-source' event.
  91. *
  92. * @param contents an array of Jingle 'content' elements.
  93. */
  94. JingleSession.prototype.addSources = function(contents) {};
  95. /**
  96. * Handles a 'remove-source' event.
  97. *
  98. * @param contents an array of Jingle 'content' elements.
  99. */
  100. JingleSession.prototype.removeSources = function(contents) {};
  101. /**
  102. * Terminates this Jingle session by sending session-terminate
  103. * @param reason XMPP Jingle error condition
  104. * @param text some meaningful error message
  105. */
  106. JingleSession.prototype.terminate = function(reason, text) {};
  107. /**
  108. * Handles an offer from the remote peer (prepares to accept a session).
  109. * @param jingle the 'jingle' XML element.
  110. * @param success callback called when we the incoming session has been accepted
  111. * @param failure callback called when we fail for any reason, will supply error
  112. * object with details(which is meant more to be printed to the logger
  113. * than analysed in the code, as the error is unrecoverable anyway)
  114. */
  115. JingleSession.prototype.acceptOffer = function(jingle, success, failure) {};
  116. module.exports = JingleSession;