Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove unused cordova events #2583

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/cozy-realtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
]
},
"dependencies": {
"@cozy/minilog": "^1.0.0",
"cozy-device-helper": "^3.1.0"
"@cozy/minilog": "^1.0.0"
}
}
59 changes: 0 additions & 59 deletions packages/cozy-realtime/src/CozyRealtime.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import MicroEE from 'microee'

import { hasNetworkInformationPlugin, isCordova } from 'cozy-device-helper'

import RetryManager from './RetryManager'
import SubscriptionList from './SubscriptionList'
import {
Expand Down Expand Up @@ -52,11 +50,6 @@ class CozyRealtime {
})
this.retryManager.on('error', err => this.emit('error', err))
this.bindEventHandlers()
if (isCordova() && !hasNetworkInformationPlugin()) {
this.logger.warn(
`This seems a Cordova app and cordova-plugin-network-information doesn't seem to be installed. Please install it from https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-network-information/ to support online and offline events.`
)
}
}

/**
Expand All @@ -73,7 +66,6 @@ class CozyRealtime {
this.retryManager.reset()
this.subscribeGlobalEvents()
this.subscribeClientEvents()
this.subscribeCordovaEvents()
this.emit('start')
if (isOnline()) this.connect()
}
Expand Down Expand Up @@ -176,7 +168,6 @@ class CozyRealtime {
stop() {
if (this.isStarted) {
this.logger.info('stopped')
this.unsubscribeCordovaEvents()
this.unsubscribeGlobalEvents()
this.unsubscribeClientEvents()
if (this.hasWebSocket()) {
Expand Down Expand Up @@ -448,9 +439,6 @@ class CozyRealtime {
this.onOnline = this.onOnline.bind(this)
this.onOffline = this.onOffline.bind(this)
this.onVisibilityChange = this.onVisibilityChange.bind(this)
// cordova events
this.onDeviceReady = this.onDeviceReady.bind(this)
this.onResume = this.onResume.bind(this)
}

/* * * * * * * * * * * * */
Expand Down Expand Up @@ -578,53 +566,6 @@ class CozyRealtime {
}
}

/* * * * * * * * * * * */
/* * Cordova EVENTS * */
/* * * * * * * * * * * */

/**
* Subscribes to cordova events
* @private
*/
subscribeCordovaEvents() {
if (isCordova()) {
document.addEventListener('deviceready', this.onDeviceReady)
document.addEventListener('resume', this.onResume)
}
}

/**
* Unsubscribes to cordova events
* @private
*/
unsubscribeCordovaEvents() {
if (isCordova()) {
document.removeEventListener('deviceready', this.onDeviceReady)
document.removeEventListener('resume', this.onResume)
}
}

/**
* when the device is ready (for Cordova)
* @private
*/
onDeviceReady() {
// online and offline events were not ready
// detach them (should not be needed, but it doesnt' harm
// and we really don't want to attach an event twice
this.unsubscribeGlobalEvents()
this.subscribeGlobalEvents()
}

/**
* when the device resumes (for Cordova)
* @see https://cordova.apache.org/docs/en/9.x/cordova/events/events.html#resume
* @private
*/
onResume() {
this.reconnect({ immediate: true })
}

/* * * * * * * * * * * * * * * */
/* * Global (browser) EVENTS * */
/* * * * * * * * * * * * * * * */
Expand Down