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.

desktopsharing.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * Indicates that desktop stream is currently in use(for toggle purpose).
  3. * @type {boolean}
  4. */
  5. var isUsingScreenStream = false;
  6. /**
  7. * Indicates that switch stream operation is in progress and prevent from triggering new events.
  8. * @type {boolean}
  9. */
  10. var switchInProgress = false;
  11. /**
  12. * @returns {boolean} <tt>true</tt> if desktop sharing feature is available and enabled.
  13. */
  14. function isDesktopSharingEnabled() {
  15. // Desktop sharing must be enabled in config and works on chrome only.
  16. // Flag 'chrome://flags/#enable-usermedia-screen-capture' must be enabled.
  17. return config.chromeDesktopSharing && RTC.browser == 'chrome';
  18. }
  19. /*
  20. * Toggles screen sharing.
  21. */
  22. function toggleScreenSharing() {
  23. if (!(connection && connection.connected
  24. && !switchInProgress
  25. && getConferenceHandler().peerconnection.signalingState == 'stable'
  26. && getConferenceHandler().peerconnection.iceConnectionState == 'connected')) {
  27. return;
  28. }
  29. switchInProgress = true;
  30. // Only the focus is able to set a shared key.
  31. if(!isUsingScreenStream)
  32. {
  33. // Enable screen stream
  34. getUserMediaWithConstraints(
  35. ['screen'],
  36. function(stream){
  37. isUsingScreenStream = true;
  38. gotScreenStream(stream);
  39. },
  40. getSwitchStreamFailed
  41. );
  42. } else {
  43. // Disable screen stream
  44. getUserMediaWithConstraints(
  45. ['video'],
  46. function(stream) {
  47. isUsingScreenStream = false;
  48. gotScreenStream(stream);
  49. },
  50. getSwitchStreamFailed, config.resolution || '360'
  51. );
  52. }
  53. }
  54. function getSwitchStreamFailed(error) {
  55. console.error("Failed to obtain the stream to switch to", error);
  56. switchInProgress = false;
  57. }
  58. function gotScreenStream(stream) {
  59. var oldStream = connection.jingle.localVideo;
  60. change_local_video(stream);
  61. // FIXME: will block switchInProgress on true value in case of exception
  62. getConferenceHandler().switchStreams(stream, oldStream, onDesktopStreamEnabled);
  63. }
  64. function onDesktopStreamEnabled() {
  65. // Wait a moment before enabling the button
  66. window.setTimeout(function() {
  67. switchInProgress = false;
  68. }, 3000);
  69. }