fix: handle pleroma ping messages (#1676)
* fix: handle pleroma ping messages fixes #1673 * refactor safeParse
This commit is contained in:
parent
1d3859a4e2
commit
79537fb8cd
|
@ -5,9 +5,9 @@ import { addStatusOrNotification } from '../addStatusOrNotification'
|
||||||
const KNOWN_EVENTS = ['update', 'delete', 'notification', 'conversation']
|
const KNOWN_EVENTS = ['update', 'delete', 'notification', 'conversation']
|
||||||
|
|
||||||
export function processMessage (instanceName, timelineName, message) {
|
export function processMessage (instanceName, timelineName, message) {
|
||||||
let { event, payload } = message
|
let { event, payload } = (message || {})
|
||||||
if (!KNOWN_EVENTS.includes(event)) {
|
if (!KNOWN_EVENTS.includes(event)) {
|
||||||
console.error("don't know how to handle event", message)
|
console.warn('ignoring message from server', message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mark('processMessage')
|
mark('processMessage')
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { lifecycle } from '../../_utils/lifecycle'
|
||||||
import { getStreamUrl } from './getStreamUrl'
|
import { getStreamUrl } from './getStreamUrl'
|
||||||
import { EventEmitter } from 'events-light'
|
import { EventEmitter } from 'events-light'
|
||||||
import { eventBus } from '../../_utils/eventBus'
|
import { eventBus } from '../../_utils/eventBus'
|
||||||
|
import { safeParse } from '../../_utils/safeParse'
|
||||||
|
|
||||||
export class TimelineStream extends EventEmitter {
|
export class TimelineStream extends EventEmitter {
|
||||||
constructor (streamingApi, accessToken, timeline) {
|
constructor (streamingApi, accessToken, timeline) {
|
||||||
|
@ -54,7 +55,7 @@ export class TimelineStream extends EventEmitter {
|
||||||
this.emit('reconnect')
|
this.emit('reconnect')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ws.onmessage = (e) => this.emit('message', JSON.parse(e.data))
|
ws.onmessage = (e) => this.emit('message', safeParse(e.data))
|
||||||
ws.onclose = () => this.emit('close')
|
ws.onclose = () => this.emit('close')
|
||||||
// The ws "onreconnect" event seems unreliable. When the server goes down and comes back up,
|
// The ws "onreconnect" event seems unreliable. When the server goes down and comes back up,
|
||||||
// it doesn't fire (but "open" does). When we freeze and unfreeze, it fires along with the
|
// it doesn't fire (but "open" does). When we freeze and unfreeze, it fires along with the
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Store } from 'svelte/store'
|
import { Store } from 'svelte/store'
|
||||||
import { safeLocalStorage as LS } from '../_utils/safeLocalStorage'
|
import { safeLocalStorage as LS } from '../_utils/safeLocalStorage'
|
||||||
import { lifecycle } from '../_utils/lifecycle'
|
import { lifecycle } from '../_utils/lifecycle'
|
||||||
import { safeParse } from './safeParse'
|
import { safeParse } from '../_utils/safeParse'
|
||||||
|
|
||||||
export class LocalStorageStore extends Store {
|
export class LocalStorageStore extends Store {
|
||||||
constructor (state, keysToWatch) {
|
constructor (state, keysToWatch) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// "lite" version of the store used in the inline script.
|
// "lite" version of the store used in the inline script.
|
||||||
|
|
||||||
import { safeParse } from './safeParse'
|
import { safeParse } from '../_utils/safeParse'
|
||||||
import { testHasLocalStorage } from '../_utils/testStorage'
|
import { testHasLocalStorage } from '../_utils/testStorage'
|
||||||
|
|
||||||
const hasLocalStorage = testHasLocalStorage()
|
const hasLocalStorage = testHasLocalStorage()
|
||||||
|
|
Loading…
Reference in a new issue