Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

simulcast.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*jslint plusplus: true */
  2. /*jslint nomen: true*/
  3. var SimulcastSender = require("./SimulcastSender");
  4. var NoSimulcastSender = SimulcastSender["no"];
  5. var NativeSimulcastSender = SimulcastSender["native"];
  6. var SimulcastReceiver = require("./SimulcastReceiver");
  7. var SimulcastUtils = require("./SimulcastUtils");
  8. /**
  9. *
  10. * @constructor
  11. */
  12. function SimulcastManager() {
  13. // Create the simulcast utilities.
  14. this.simulcastUtils = new SimulcastUtils();
  15. // Create remote simulcast.
  16. this.simulcastReceiver = new SimulcastReceiver();
  17. // Initialize local simulcast.
  18. // TODO(gp) move into SimulcastManager.prototype.getUserMedia and take into
  19. // account constraints.
  20. if (!config.enableSimulcast) {
  21. this.simulcastSender = new NoSimulcastSender();
  22. } else {
  23. var isChromium = window.chrome,
  24. vendorName = window.navigator.vendor;
  25. if(isChromium !== null && isChromium !== undefined
  26. /* skip opera */
  27. && vendorName === "Google Inc."
  28. /* skip Chromium as suggested by fippo */
  29. && !window.navigator.appVersion.match(/Chromium\//) ) {
  30. var ver = parseInt(window.navigator.appVersion.match(/Chrome\/(\d+)\./)[1], 10);
  31. if (ver > 37) {
  32. this.simulcastSender = new NativeSimulcastSender();
  33. } else {
  34. this.simulcastSender = new NoSimulcastSender();
  35. }
  36. } else {
  37. this.simulcastSender = new NoSimulcastSender();
  38. }
  39. }
  40. }
  41. /**
  42. * Restores the simulcast groups of the remote description. In
  43. * transformRemoteDescription we remove those in order for the set remote
  44. * description to succeed. The focus needs the signal the groups to new
  45. * participants.
  46. *
  47. * @param desc
  48. * @returns {*}
  49. */
  50. SimulcastManager.prototype.reverseTransformRemoteDescription = function (desc) {
  51. return this.simulcastReceiver.reverseTransformRemoteDescription(desc);
  52. };
  53. /**
  54. * Removes the ssrc-group:SIM from the remote description bacause Chrome
  55. * either gets confused and thinks this is an FID group or, if an FID group
  56. * is already present, it fails to set the remote description.
  57. *
  58. * @param desc
  59. * @returns {*}
  60. */
  61. SimulcastManager.prototype.transformRemoteDescription = function (desc) {
  62. return this.simulcastReceiver.transformRemoteDescription(desc);
  63. };
  64. /**
  65. * Gets the fully qualified msid (stream.id + track.id) associated to the
  66. * SSRC.
  67. *
  68. * @param ssrc
  69. * @returns {*}
  70. */
  71. SimulcastManager.prototype.getRemoteVideoStreamIdBySSRC = function (ssrc) {
  72. return this.simulcastReceiver.getRemoteVideoStreamIdBySSRC(ssrc);
  73. };
  74. /**
  75. * Returns a stream with single video track, the one currently being
  76. * received by this endpoint.
  77. *
  78. * @param stream the remote simulcast stream.
  79. * @returns {webkitMediaStream}
  80. */
  81. SimulcastManager.prototype.getReceivingVideoStream = function (stream) {
  82. return this.simulcastReceiver.getReceivingVideoStream(stream);
  83. };
  84. /**
  85. *
  86. *
  87. * @param desc
  88. * @returns {*}
  89. */
  90. SimulcastManager.prototype.transformLocalDescription = function (desc) {
  91. return this.simulcastSender.transformLocalDescription(desc);
  92. };
  93. /**
  94. *
  95. * @returns {*}
  96. */
  97. SimulcastManager.prototype.getLocalVideoStream = function() {
  98. return this.simulcastSender.getLocalVideoStream();
  99. };
  100. /**
  101. * GUM for simulcast.
  102. *
  103. * @param constraints
  104. * @param success
  105. * @param err
  106. */
  107. SimulcastManager.prototype.getUserMedia = function (constraints, success, err) {
  108. this.simulcastSender.getUserMedia(constraints, success, err);
  109. };
  110. /**
  111. * Prepares the local description for public usage (i.e. to be signaled
  112. * through Jingle to the focus).
  113. *
  114. * @param desc
  115. * @returns {RTCSessionDescription}
  116. */
  117. SimulcastManager.prototype.reverseTransformLocalDescription = function (desc) {
  118. return this.simulcastSender.reverseTransformLocalDescription(desc);
  119. };
  120. /**
  121. * Ensures that the simulcast group is present in the answer, _if_ native
  122. * simulcast is enabled,
  123. *
  124. * @param desc
  125. * @returns {*}
  126. */
  127. SimulcastManager.prototype.transformAnswer = function (desc) {
  128. return this.simulcastSender.transformAnswer(desc);
  129. };
  130. SimulcastManager.prototype.getReceivingSSRC = function (jid) {
  131. return this.simulcastReceiver.getReceivingSSRC(jid);
  132. };
  133. SimulcastManager.prototype.getReceivingVideoStreamBySSRC = function (msid) {
  134. return this.simulcastReceiver.getReceivingVideoStreamBySSRC(msid);
  135. };
  136. /**
  137. *
  138. * @param lines
  139. * @param mediatypes
  140. * @returns {*}
  141. */
  142. SimulcastManager.prototype.parseMedia = function(lines, mediatypes) {
  143. var sb = lines.sdp.split('\r\n');
  144. return this.simulcastUtils.parseMedia(sb, mediatypes);
  145. };
  146. SimulcastManager.prototype._setReceivingVideoStream = function(resource, ssrc) {
  147. this.simulcastReceiver._setReceivingVideoStream(resource, ssrc);
  148. };
  149. SimulcastManager.prototype._setLocalVideoStreamEnabled = function(ssrc, enabled) {
  150. this.simulcastSender._setLocalVideoStreamEnabled(ssrc, enabled);
  151. };
  152. SimulcastManager.prototype.resetSender = function() {
  153. if (typeof this.simulcastSender.reset === 'function'){
  154. this.simulcastSender.reset();
  155. }
  156. };
  157. $(document).bind('simulcastlayerschanged', function (event, endpointSimulcastLayers) {
  158. endpointSimulcastLayers.forEach(function (esl) {
  159. var ssrc = esl.simulcastLayer.primarySSRC;
  160. simulcast._setReceivingVideoStream(esl.endpoint, ssrc);
  161. });
  162. });
  163. $(document).bind('startsimulcastlayer', function (event, simulcastLayer) {
  164. var ssrc = simulcastLayer.primarySSRC;
  165. simulcast._setLocalVideoStreamEnabled(ssrc, true);
  166. });
  167. $(document).bind('stopsimulcastlayer', function (event, simulcastLayer) {
  168. var ssrc = simulcastLayer.primarySSRC;
  169. simulcast._setLocalVideoStreamEnabled(ssrc, false);
  170. });
  171. var simulcast = new SimulcastManager();
  172. module.exports = simulcast;