Skip to content

Commit d28681d

Browse files
committed
fix: potential w2g errors
1 parent e5cda31 commit d28681d

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

common/views/WatchTogether/Lobby.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import Message from './Message.svelte'
55
import { SendHorizontal, DoorOpen, UserPlus } from 'lucide-svelte'
66
export let invite
7+
8+
/** @type {import('simple-store-svelte').Writable<import('./w2g.js').W2GClient | null>} */
79
export let state
810
911
function cleanup () {

common/views/WatchTogether/Message.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
</script>
1515

1616
<div class='message d-flex flex-row mt-15' class:flex-row={incoming} class:flex-row-reverse={!incoming}>
17-
<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' />
17+
<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' />
1818
<div class='d-flex flex-column px-10 align-items-start flex-auto' class:align-items-start={incoming} class:align-items-end={!incoming}>
1919
<div class='pb-5 d-flex flex-row align-items-center px-5'>
2020
<div class='font-weight-bold font-size-18 line-height-normal'>
21-
{user.name || 'Anonymous'}
21+
{user?.name || 'Anonymous'}
2222
</div>
2323
<div class='text-muted pl-10 font-size-12 line-height-normal'>
2424
{time.toLocaleTimeString()}

common/views/WatchTogether/User.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
</script>
99

1010
<div class='d-flex align-items-center pb-10'>
11-
<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' />
11+
<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' />
1212
<div class='font-size-18 line-height-normal pl-5'>
13-
{user.name || 'Anonymous'}
13+
{user?.name || 'Anonymous'}
1414
</div>
15-
{#if user.name}
15+
{#if user?.name}
1616
<span class='pointer text-primary d-flex align-items-center ml-auto' use:click={() => IPC.emit('open', 'https://anilist.co/user/' + user.name)}>
1717
<ExternalLink size='2rem' />
1818
</span>

common/views/WatchTogether/w2g.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ export class W2GClient extends EventEmitter {
103103
}
104104

105105
_playerStateChanged (state) {
106-
debug(`_playerStateChanged: ${this.player.paused} ${state.paused} ${this.player.time} ${state.time}`)
106+
debug(`_playerStateChanged: ${this.player?.paused} ${state?.paused} ${this.player?.time} ${state?.time}`)
107+
if (!state) return false
107108
if (this.player.paused !== state.paused || this.player.time !== state.time) {
108109
this.player = state
109110
return true
@@ -177,6 +178,7 @@ export class W2GClient extends EventEmitter {
177178
})
178179
break
179180
case EventTypes.MagnetLinkEvent: {
181+
if (data.payload?.magnet === undefined) break
180182
const { hash, magnet } = data.payload
181183
if (hash !== this.magnet?.hash) {
182184
this.isHost = false
@@ -187,13 +189,15 @@ export class W2GClient extends EventEmitter {
187189
break
188190
}
189191
case EventTypes.MediaIndexEvent: {
192+
if (data.payload?.index === undefined) break
190193
if (this.index !== data.payload.index) {
191194
this.index = data.payload.index
192195
this.emit('index', data.payload.index)
193196
}
194197
break
195198
}
196199
case EventTypes.PlayerStateEvent: {
200+
if (data.payload?.time === undefined) break
197201
if (this._playerStateChanged(data.payload)) this.emit('player', data.payload)
198202
break
199203
}

0 commit comments

Comments
 (0)