fix: potential w2g errors

This commit is contained in:
ThaUnknown 2024-08-27 19:47:17 +02:00
parent e5cda31e78
commit d28681d44c
4 changed files with 12 additions and 6 deletions

View file

@ -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 () {

View file

@ -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()}

View file

@ -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>

View file

@ -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
@ -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
@ -187,6 +189,7 @@ 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)
@ -194,6 +197,7 @@ export class W2GClient extends EventEmitter {
break
}
case EventTypes.PlayerStateEvent: {
if (data.payload?.time === undefined) break
if (this._playerStateChanged(data.payload)) this.emit('player', data.payload)
break
}