diff options
| author | stonedDiscord <Tukz@gmx.de> | 2022-08-30 22:39:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-30 22:39:43 +0200 |
| commit | cced5e71d9004eaf34156935d214eac82204ab4b (patch) | |
| tree | af3481664cebef9e0f1afbfe74629084c897ec40 /webAO/packets/handlers/handleRMC.ts | |
| parent | 325aa41d1216facbb7228743930a8ad21afec7aa (diff) | |
| parent | 3d6e61c6b0962cea539c6d780d68a7ad0b64bee1 (diff) | |
Merge pull request #155 from caleb-mabry/move-two-packets
Move three packets
Diffstat (limited to 'webAO/packets/handlers/handleRMC.ts')
| -rw-r--r-- | webAO/packets/handlers/handleRMC.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/webAO/packets/handlers/handleRMC.ts b/webAO/packets/handlers/handleRMC.ts new file mode 100644 index 0000000..ada1ad2 --- /dev/null +++ b/webAO/packets/handlers/handleRMC.ts @@ -0,0 +1,24 @@ +import { client } from '../../client' +// TODO BUG: +// this.viewport.music is an array. Therefore you must access elements +/** + * Handles a music change to an arbitrary resource, with an offset in seconds. + * @param {Array} args packet arguments + */ +export const handleRMC = (args: string[]) => { + client.viewport.music.pause(); + const { music } = client.viewport; + // Music offset + drift from song loading + music.totime = args[1]; + music.offset = new Date().getTime() / 1000; + music.addEventListener( + "loadedmetadata", + () => { + music.currentTime += parseFloat( + music.totime + (new Date().getTime() / 1000 - music.offset) + ).toFixed(3); + music.play(); + }, + false + ); +}
\ No newline at end of file |
