fix: handle pleroma ping messages (#1676)

* fix: handle pleroma ping messages

fixes #1673

* refactor safeParse
This commit is contained in:
Nolan Lawson 2019-12-15 09:58:00 -08:00 committed by GitHub
parent 1d3859a4e2
commit 79537fb8cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 5 deletions

View file

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

View file

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

View file

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

View file

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