Skip to content

Commit

Permalink
fix: Do not handle {add,remove}EventListener when not in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrowne committed Jan 9, 2020
1 parent c5da980 commit 19d10e2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/cozy-realtime/src/CozyRealtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import MicroEE from 'microee'
import Socket from './Socket'
import minilog_ from 'minilog'

const minilog = (typeof window !== 'undefined' && window.minilog) || minilog_
const inBrowser = typeof window !== 'undefined'
const minilog = (inBrowser && window.minilog) || minilog_
const logger = minilog('cozy-realtime')
minilog.suggest.deny('cozy-realtime', 'info')

Expand Down Expand Up @@ -163,7 +164,7 @@ class CozyRealtime {
this._cozyClient.on('tokenRefreshed', this._updateAuthentication)
this._cozyClient.on('logout', this.unsubscribeAll)

if (global) {
if (inBrowser) {
global.addEventListener('beforeunload', this._beforeUnload)
global.addEventListener('online', this._resubscribe)
global.removeEventListener('offline', this._resetSocket)
Expand Down

0 comments on commit 19d10e2

Please sign in to comment.