File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed
Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -281,16 +281,26 @@ function onWindowResize(): void {
281281 renderTimeline ( ) ;
282282}
283283
284+ let pauseIfAnotherPlayerStartsHandle : ReturnType < typeof setInterval > | null = null ;
285+ function pauseIfAnotherPlayerStarts ( ) : void {
286+ if ( ! synth . playing ) {
287+ clearInterval ( pauseIfAnotherPlayerStartsHandle ! ) ;
288+ return ;
289+ }
290+
291+ const storedPlayerId : string | null = getLocalStorage ( "playerId" ) ;
292+ if ( storedPlayerId != null && storedPlayerId != id ) {
293+ onTogglePlay ( ) ;
294+ renderPlayhead ( ) ;
295+ clearInterval ( pauseIfAnotherPlayerStartsHandle ! ) ;
296+ }
297+ }
298+
284299function animate ( ) : void {
285300 if ( synth . playing ) {
286301 animationRequest = requestAnimationFrame ( animate ) ;
287- const storedPlayerId : string | null = getLocalStorage ( "playerId" ) ;
288- if ( storedPlayerId != null && storedPlayerId != id ) {
289- onTogglePlay ( ) ;
290- }
291302 renderPlayhead ( ) ;
292303 }
293-
294304 if ( pauseButtonDisplayed != synth . playing ) {
295305 renderPlayButton ( ) ;
296306 }
@@ -306,6 +316,8 @@ function onTogglePlay(): void {
306316 synth . play ( ) ;
307317 setLocalStorage ( "playerId" , id ) ;
308318 animate ( ) ;
319+ clearInterval ( pauseIfAnotherPlayerStartsHandle ! ) ;
320+ pauseIfAnotherPlayerStartsHandle = setInterval ( pauseIfAnotherPlayerStarts , 100 ) ;
309321 }
310322 }
311323 renderPlayButton ( ) ;
@@ -337,6 +349,7 @@ function onTimelineMouseDown(event: MouseEvent): void {
337349}
338350
339351function onTimelineMouseMove ( event : MouseEvent ) : void {
352+ if ( ! draggingPlayhead ) return ;
340353 event . preventDefault ( ) ;
341354 onTimelineCursorMove ( event . clientX || event . pageX ) ;
342355}
You can’t perform that action at this time.
0 commit comments