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.

simulcast.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. RTC.addListener(RTCEvents.SIMULCAST_LAYER_CHANGED,
  41. function (endpointSimulcastLayers) {
  42. endpointSimulcastLayers.forEach(function (esl) {
  43. var ssrc = esl.simulcastLayer.primarySSRC;
  44. simulcast._setReceivingVideoStream(esl.endpoint, ssrc);
  45. });
  46. });
  47. RTC.addListener(RTCEvents.SIMULCAST_START, function (simulcastLayer) {
  48. var ssrc = simulcastLayer.primarySSRC;
  49. simulcast._setLocalVideoStreamEnabled(ssrc, true);
  50. });
  51. RTC.addListener(RTCEvents.SIMULCAST_STOP, function (simulcastLayer) {
  52. var ssrc = simulcastLayer.primarySSRC;
  53. simulcast._setLocalVideoStreamEnabled(ssrc, false);
  54. });
  55. }
  56. /**
  57. * Restores the simulcast groups of the remote description. In
  58. * transformRemoteDescription we remove those in order for the set remote
  59. * description to succeed. The focus needs the signal the groups to new
  60. * participants.
  61. *
  62. * @param desc
  63. * @returns {*}
  64. */
  65. SimulcastManager.prototype.reverseTransformRemoteDescription = function (desc) {
  66. return this.simulcastReceiver.reverseTransformRemoteDescription(desc);
  67. };
  68. /**
  69. * Removes the ssrc-group:SIM from the remote description bacause Chrome
  70. * either gets confused and thinks this is an FID group or, if an FID group
  71. * is already present, it fails to set the remote description.
  72. *
  73. * @param desc
  74. * @returns {*}
  75. */
  76. SimulcastManager.prototype.transformRemoteDescription = function (desc) {
  77. return this.simulcastReceiver.transformRemoteDescription(desc);
  78. };
  79. /**
  80. * Gets the fully qualified msid (stream.id + track.id) associated to the
  81. * SSRC.
  82. *
  83. * @param ssrc
  84. * @returns {*}
  85. */
  86. SimulcastManager.prototype.getRemoteVideoStreamIdBySSRC = function (ssrc) {
  87. return this.simulcastReceiver.getRemoteVideoStreamIdBySSRC(ssrc);
  88. };
  89. /**
  90. * Returns a stream with single video track, the one currently being
  91. * received by this endpoint.
  92. *
  93. * @param stream the remote simulcast stream.
  94. * @returns {webkitMediaStream}
  95. */
  96. SimulcastManager.prototype.getReceivingVideoStream = function (stream) {
  97. return this.simulcastReceiver.getReceivingVideoStream(stream);
  98. };
  99. /**
  100. *
  101. *
  102. * @param desc
  103. * @returns {*}
  104. */
  105. SimulcastManager.prototype.transformLocalDescription = function (desc) {
  106. return this.simulcastSender.transformLocalDescription(desc);
  107. };
  108. /**
  109. *
  110. * @returns {*}
  111. */
  112. SimulcastManager.prototype.getLocalVideoStream = function() {
  113. return this.simulcastSender.getLocalVideoStream();
  114. };
  115. /**
  116. * GUM for simulcast.
  117. *
  118. * @param constraints
  119. * @param success
  120. * @param err
  121. */
  122. SimulcastManager.prototype.getUserMedia = function (constraints, success, err) {
  123. this.simulcastSender.getUserMedia(constraints, success, err);
  124. };
  125. /**
  126. * Prepares the local description for public usage (i.e. to be signaled
  127. * through Jingle to the focus).
  128. *
  129. * @param desc
  130. * @returns {RTCSessionDescription}
  131. */
  132. SimulcastManager.prototype.reverseTransformLocalDescription = function (desc) {
  133. return this.simulcastSender.reverseTransformLocalDescription(desc);
  134. };
  135. /**
  136. * Ensures that the simulcast group is present in the answer, _if_ native
  137. * simulcast is enabled,
  138. *
  139. * @param desc
  140. * @returns {*}
  141. */
  142. SimulcastManager.prototype.transformAnswer = function (desc) {
  143. return this.simulcastSender.transformAnswer(desc);
  144. };
  145. SimulcastManager.prototype.getReceivingSSRC = function (jid) {
  146. return this.simulcastReceiver.getReceivingSSRC(jid);
  147. };
  148. SimulcastManager.prototype.getReceivingVideoStreamBySSRC = function (msid) {
  149. return this.simulcastReceiver.getReceivingVideoStreamBySSRC(msid);
  150. };
  151. /**
  152. *
  153. * @param lines
  154. * @param mediatypes
  155. * @returns {*}
  156. */
  157. SimulcastManager.prototype.parseMedia = function(lines, mediatypes) {
  158. var sb = lines.sdp.split('\r\n');
  159. return this.simulcastUtils.parseMedia(sb, mediatypes);
  160. };
  161. SimulcastManager.prototype._setReceivingVideoStream = function(resource, ssrc) {
  162. this.simulcastReceiver._setReceivingVideoStream(resource, ssrc);
  163. };
  164. SimulcastManager.prototype._setLocalVideoStreamEnabled = function(ssrc, enabled) {
  165. this.simulcastSender._setLocalVideoStreamEnabled(ssrc, enabled);
  166. };
  167. SimulcastManager.prototype.resetSender = function() {
  168. if (typeof this.simulcastSender.reset === 'function'){
  169. this.simulcastSender.reset();
  170. }
  171. };
  172. var simulcast = new SimulcastManager();
  173. module.exports = simulcast;