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.

TalkMutedDetection.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. var JitsiTrackEvents = require('../../JitsiTrackEvents');
  2. /**
  3. * Creates TalkMutedDetection
  4. * @param callback the callback to call when detected local user is talking
  5. * while its microphone is muted.
  6. * @constructor
  7. */
  8. function TalkMutedDetection(callback) {
  9. this.callback = callback;
  10. // we track firing the event, in order to avoid sending too many events
  11. this.eventFired = false;
  12. }
  13. /**
  14. * Receives audio level events for all send/receive streams.
  15. * @param ssrc the ssrc of the stream
  16. * @param level the current audio level
  17. * @param isLocal whether this is local or remote stream (sent or received)
  18. */
  19. TalkMutedDetection.prototype.audioLevelListener =
  20. function (ssrc, level, isLocal) {
  21. // we are interested only in local audio stream
  22. // and if event is not already sent
  23. if (!isLocal || !this.audioTrack || this.eventFired)
  24. return;
  25. if (this.audioTrack.isMuted() && level > 0.02) {
  26. this.eventFired = true;
  27. this.callback();
  28. }
  29. };
  30. /**
  31. * Mute changed for a track.
  32. * @param track the track which mute state has changed.
  33. */
  34. TalkMutedDetection.prototype.muteChanged = function (track) {
  35. if (!track.isLocal() || !track.isAudioTrack())
  36. return;
  37. if (track.isMuted())
  38. this.eventFired = false;
  39. };
  40. /**
  41. * Adds local tracks. We are interested only in the audio one.
  42. * @param track
  43. */
  44. TalkMutedDetection.prototype.addTrack = function(track){
  45. if (!track.isAudioTrack())
  46. return;
  47. this.audioTrack = track;
  48. };
  49. module.exports = TalkMutedDetection;