Skip to content

Commit

Permalink
fix: potential w2g errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaUnknown committed Aug 27, 2024
1 parent e5cda31 commit d28681d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions common/views/WatchTogether/Lobby.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import Message from './Message.svelte'
import { SendHorizontal, DoorOpen, UserPlus } from 'lucide-svelte'
export let invite
/** @type {import('simple-store-svelte').Writable<import('./w2g.js').W2GClient | null>} */
export let state
function cleanup () {
Expand Down
4 changes: 2 additions & 2 deletions common/views/WatchTogether/Message.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
</script>

<div class='message d-flex flex-row mt-15' class:flex-row={incoming} class:flex-row-reverse={!incoming}>
<img src={user.avatar?.medium || 'https://s4.anilist.co/file/anilistcdn/user/avatar/large/default.png'} alt='ProfilePicture' class='w-50 h-50 rounded-circle p-5 mt-auto' />
<img src={user?.avatar?.medium || 'https://s4.anilist.co/file/anilistcdn/user/avatar/large/default.png'} alt='ProfilePicture' class='w-50 h-50 rounded-circle p-5 mt-auto' />
<div class='d-flex flex-column px-10 align-items-start flex-auto' class:align-items-start={incoming} class:align-items-end={!incoming}>
<div class='pb-5 d-flex flex-row align-items-center px-5'>
<div class='font-weight-bold font-size-18 line-height-normal'>
{user.name || 'Anonymous'}
{user?.name || 'Anonymous'}
</div>
<div class='text-muted pl-10 font-size-12 line-height-normal'>
{time.toLocaleTimeString()}
Expand Down
6 changes: 3 additions & 3 deletions common/views/WatchTogether/User.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
</script>

<div class='d-flex align-items-center pb-10'>
<img src={user.avatar?.medium || 'https://s4.anilist.co/file/anilistcdn/user/avatar/large/default.png'} alt='ProfilePicture' class='w-50 h-50 rounded-circle p-5 mt-auto' />
<img src={user?.avatar?.medium || 'https://s4.anilist.co/file/anilistcdn/user/avatar/large/default.png'} alt='ProfilePicture' class='w-50 h-50 rounded-circle p-5 mt-auto' />
<div class='font-size-18 line-height-normal pl-5'>
{user.name || 'Anonymous'}
{user?.name || 'Anonymous'}
</div>
{#if user.name}
{#if user?.name}
<span class='pointer text-primary d-flex align-items-center ml-auto' use:click={() => IPC.emit('open', 'https://anilist.co/user/' + user.name)}>
<ExternalLink size='2rem' />
</span>
Expand Down
6 changes: 5 additions & 1 deletion common/views/WatchTogether/w2g.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ export class W2GClient extends EventEmitter {
}

_playerStateChanged (state) {
debug(`_playerStateChanged: ${this.player.paused} ${state.paused} ${this.player.time} ${state.time}`)
debug(`_playerStateChanged: ${this.player?.paused} ${state?.paused} ${this.player?.time} ${state?.time}`)
if (!state) return false
if (this.player.paused !== state.paused || this.player.time !== state.time) {
this.player = state
return true
Expand Down Expand Up @@ -177,6 +178,7 @@ export class W2GClient extends EventEmitter {
})
break
case EventTypes.MagnetLinkEvent: {
if (data.payload?.magnet === undefined) break
const { hash, magnet } = data.payload
if (hash !== this.magnet?.hash) {
this.isHost = false
Expand All @@ -187,13 +189,15 @@ export class W2GClient extends EventEmitter {
break
}
case EventTypes.MediaIndexEvent: {
if (data.payload?.index === undefined) break
if (this.index !== data.payload.index) {
this.index = data.payload.index
this.emit('index', data.payload.index)
}
break
}
case EventTypes.PlayerStateEvent: {
if (data.payload?.time === undefined) break
if (this._playerStateChanged(data.payload)) this.emit('player', data.payload)
break
}
Expand Down

0 comments on commit d28681d

Please sign in to comment.