(event: KeyboardEvent)
| 365 | } |
| 366 | let volumeSetTimeout: ReturnType<typeof setInterval> | null = null; |
| 367 | const handleKeyPress = (event: KeyboardEvent) => { |
| 368 | const isShiftPressed = event.shiftKey; |
| 369 | const isModifierPressed = event.metaKey || event.ctrlKey || event.altKey; |
| 370 | const activeElement = document.activeElement; |
| 371 | |
| 372 | const tracks: TextTrackList = player.textTracks(); |
| 373 | |
| 374 | if ( |
| 375 | activeElement?.tagName.toLowerCase() === 'input' || |
| 376 | activeElement?.tagName.toLowerCase() === 'textarea' || |
| 377 | isModifierPressed |
| 378 | ) { |
| 379 | return; // Do nothing if the active element is an input or textarea |
| 380 | } |
| 381 | if (event.code === 'KeyT') { |
| 382 | player.playbackRate(2); |
| 383 | } |
| 384 | if (isShiftPressed) { |
| 385 | const currentIndexPeriod: number = PLAYBACK_RATES.indexOf( |
| 386 | player.playbackRate(), |
| 387 | ); |
| 388 | const newIndexPeriod: number = |
| 389 | currentIndexPeriod !== PLAYBACK_RATES.length - 1 |
| 390 | ? currentIndexPeriod + 1 |
| 391 | : currentIndexPeriod; |
| 392 | const currentIndexComma = PLAYBACK_RATES.indexOf(player.playbackRate()); |
| 393 | const newIndexComma = |
| 394 | currentIndexComma !== 0 ? currentIndexComma - 1 : currentIndexComma; |
| 395 | const currentIndexUp = VOLUME_LEVELS.indexOf(player.volume()); |
| 396 | const newIndexUp = |
| 397 | currentIndexUp !== VOLUME_LEVELS.length - 1 |
| 398 | ? currentIndexUp + 1 |
| 399 | : currentIndexUp; |
| 400 | const currentIndexDown = VOLUME_LEVELS.indexOf(player.volume()); |
| 401 | const newIndexDown = |
| 402 | currentIndexDown !== 0 ? currentIndexDown - 1 : currentIndexDown; |
| 403 | switch (event.code) { |
| 404 | case 'Period': // Increase playback speed |
| 405 | player.playbackRate(PLAYBACK_RATES[newIndexPeriod]); |
| 406 | event.stopPropagation(); |
| 407 | break; |
| 408 | case 'Comma': // Decrease playback speed |
| 409 | player.playbackRate(PLAYBACK_RATES[newIndexComma]); |
| 410 | event.stopPropagation(); |
| 411 | break; |
| 412 | case 'ArrowUp': // Increase volume |
| 413 | videoRef.current?.children[0].children[6].children[3].classList.add( |
| 414 | 'vjs-hover', |
| 415 | ); |
| 416 | if (volumeSetTimeout !== null) clearTimeout(volumeSetTimeout); |
| 417 | volumeSetTimeout = setTimeout(() => { |
| 418 | videoRef.current?.children[0].children[6].children[3].classList.remove( |
| 419 | 'vjs-hover', |
| 420 | ); |
| 421 | }, 1000); |
| 422 | player.volume(VOLUME_LEVELS[newIndexUp]); |
| 423 | event.stopPropagation(); |
| 424 | break; |
nothing calls this directly
no test coverage detected