From d5e30271061cd360aa89e72ea40580a045cf2bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5var=20Aamb=C3=B8=20Fosstveit?= Date: Tue, 30 Oct 2018 14:27:57 +0100 Subject: [PATCH] Added notification sound on new peer and new chat --- app/lib/LastN.js | 135 -------------------------------- app/lib/RoomClient.js | 32 ++++++++ app/resources/sounds/notify.mp3 | Bin 0 -> 3470 bytes 3 files changed, 32 insertions(+), 135 deletions(-) delete mode 100644 app/lib/LastN.js create mode 100644 app/resources/sounds/notify.mp3 diff --git a/app/lib/LastN.js b/app/lib/LastN.js deleted file mode 100644 index 99b2e7f..0000000 --- a/app/lib/LastN.js +++ /dev/null @@ -1,135 +0,0 @@ -import { EventEmitter } from 'events'; -import Logger from './Logger'; - -const logger = new Logger('LastN'); - -export default class LastN extends EventEmitter -{ - constructor(lastNCount, room) - { - super(); - - this._room = room; - this._lastNCount = lastNCount; - this._peerList = []; - this._currentLastN = []; - this._started = false; - } - - start() - { - const peers = this._room.peers; - - for (const peer of peers) - { - this._handlePeer(peer); - } - - this._handleRoom(); - - this._started = true; - this._lastNUpdated(); - } - - peerInLastN(peerName) - { - if (this._started) - { - return this._currentLastN.indexOf(peerName) !== -1; - } - else - { - return false; - } - } - - _handleRoom() - { - this._room.on('newpeer', (peer) => - { - logger.debug( - 'lastN room "newpeer" event [name:"%s", peer:%o]', peer.name, peer); - this._handlePeer(peer); - }); - } - - addSpeakerList(speakerList) - { - this._peerList = [ ...new Set([ ...speakerList, ...this._peerList ]) ]; - - if (this._started) - this._lastNUpdated(); - } - - _handlePeer(peer) - { - logger.debug('_lastN _handlePeer() [peerName:"%s"]', peer.name); - - if (this._peerList.indexOf(peer.name) === -1) // We don't have this peer in the list - { - peer.on('close', () => - { - const index = this._peerList.indexOf(peer.name); - - if (index > -1) // We have this peer in the list, remove - { - this._peerList.splice(index, 1); - - this._lastNUpdated(); - } - }); - - logger.debug('_handlePeer() | adding peer [peerName:"%s"]', peer.name); - - this._peerList.push(peer.name); - - this._lastNUpdated(); - } - } - - handleActiveSpeaker(peerName) - { - logger.debug('handleActiveSpeaker() [peerName:"%s"]', peerName); - - const index = this._peerList.indexOf(peerName); - - if (index > -1) - { - this._peerList.splice(index, 1); - this._peerList = [ peerName ].concat(this._peerList); - - this._lastNUpdated(); - } - } - - _lastNUpdated() - { - if ( - !this._arraysEqual( - this._currentLastN, this._peerList.slice(0, this._lastNCount) - ) - ) - { - logger.debug('_lastNUpdated() | lastN is updated, emitting'); - - this._currentLastN = this._peerList.slice(0, this._lastNCount); - this.emit('lastn-updated', this._currentLastN); - } - else - logger.debug('_lastNUpdated() | lastN not updated'); - } - - _arraysEqual(arr1, arr2) - { - if (arr1.length !== arr2.length) - return false; - - for (let i = arr1.length; i--;) - { - if (arr1[i] !== arr2[i]) - return false; - } - - return true; - } -} diff --git a/app/lib/RoomClient.js b/app/lib/RoomClient.js index 54f6fa0..c52fe0b 100644 --- a/app/lib/RoomClient.js +++ b/app/lib/RoomClient.js @@ -65,6 +65,9 @@ export default class RoomClient // My peer name. this._peerName = peerName; + // Alert sound + this._soundAlert = new Audio('/resources/sounds/notify.mp3'); + // Socket.io peer connection this._signalingSocket = io(signalingUrl); @@ -1112,6 +1115,23 @@ export default class RoomClient this._dispatch( stateActions.addResponseMessage({ ...chatMessage, peerName })); + + if (!this._getState().toolarea.toolAreaOpen || + (this._getState().toolarea.toolAreaOpen && + this._getState().toolarea.currentToolTab !== 'chat')) // Make sound + { + const alertPromise = this._soundAlert.play(); + + if (alertPromise !== undefined) + { + alertPromise + .then() + .catch((error) => + { + logger.error('_soundAlert.play() | failed: %o', error); + }); + } + } }); this._signalingSocket.on('file-receive', (data) => @@ -1173,6 +1193,18 @@ export default class RoomClient logger.debug( 'room "newpeer" event [name:"%s", peer:%o]', peer.name, peer); + const alertPromise = this._soundAlert.play(); + + if (alertPromise !== undefined) + { + alertPromise + .then() + .catch((error) => + { + logger.error('_soundAlert.play() | failed: %o', error); + }); + } + this._handlePeer(peer); }); diff --git a/app/resources/sounds/notify.mp3 b/app/resources/sounds/notify.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..cd09ed59f342a83da59c76dfc09370a606ba50bf GIT binary patch literal 3470 zcmeH}do)yQAIG1$7?bNzt|jAoR4(Hh&M705ap_fVLt$J-2&04|?`*lI2vHNN5ku6t zB*`VlwL+x}xkMr)=eQIR#(u{-=l#P!XRUXw_pf)opSAbed#~^F{GQ+5-}U=Fn`Eww z1{;JskjZ4;RU80RkY@nxw1?Me&tM-A6r!gC{?f!YH2+|p7EV1K>Q4&>gnvsrc#=0Q zD8%!OzgHmj&$*$%Ka>{qX8?P93tn(h-Y6T-a9@2rO&udmZGs+vSJO6D|654GzBJwd z{y$G)5n!?jk4?}waeFh3oA|g1coUnm{3|`>zfJRhQ{)-s0|4@%^pTstQGgy(YL1Bo z66wdxjRpXC2vH*dp7-K6tH|H?e&F*tIxHK*84bPrX-7gVp2!o>8emva!Vt6a%Ndm9 z>9Lq~w>A0kSDp1HoeggAw~=KNez_L;UTom9_eGHqvvC9}dyVPM-?TImn~ao=S%Tr^ zG#nbie~w7R2}z+*g8WS!qITVyyeK^R6-^-G&?o@#*j^nVjt0d;uE(h|iat|2Dd4at zsCWW5RDTLdJj_SO2VEV*7b-^ck%~-RuN?3FQ>6XShzB_}S2;VwW@NRHe1pt*i$X z#?E^rlfU#PU#o>DJK}!U*frb;X}EDp_Py%@eJw{{IXn@+N>J zpo8C9DFDe3^f6}N#J8m^f)?8k*X^xq%6eU>*T`emsV@Jlb3l2bS`!jtvUbK=T*1WT z>AsA$aFWdmjkA^>7!upx`c5&+xZHUzK=D`j#q>w(ZMU3CexJ#6SPb9_&s601b@XbE z=)1(%s9ReYz^vQF{gwI3!!1R6c>w@yVFC4UXAOF>xe6BfgAaj#EDtmMF$&2yTyC|V z+yzy{Ga~q#E*KtU;87sNhL0FX7PDS>fXYpcCuMORYEr`@XLWugWS}JpLOyTJmzh8I z=4!r}%P(#l-iPhg=4!ZS$@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