Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

simulcast.js 5.8KB

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