您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

JingleSession.js 3.9KB

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