mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-04-27 05:10:12 +08:00
fix(network): bind listener to document instead of window (#2622)
We noticed that in some cases network state listeners are stopped triggering, but `navigator.onLine` still reflects the state correctly. I used the following code to debug and found out an issue with `window` and `document` difference: ```js window.addEventListener("online", ()=>console.warn('WINDOW ONLINE'), false); // won't be triggered window.addEventListener("online", ()=>console.warn('WINDOW ONLINE'), false); // won't be triggered document.addEventListener("online", ()=>console.warn('DOCUMENT ONLINE'), false); // triggered document.addEventListener("online", ()=>console.warn('DOCUMENT ONLINE'), false); // triggered ``` Also, according to plugin documentation, listeners should be bound to `document`: https://github.com/apache/cordova-plugin-network-information#offline
This commit is contained in:
parent
4f26069ca6
commit
d10777a33b
@ -89,7 +89,8 @@ export class Network extends IonicNativePlugin {
|
|||||||
*/
|
*/
|
||||||
@Cordova({
|
@Cordova({
|
||||||
eventObservable: true,
|
eventObservable: true,
|
||||||
event: 'offline'
|
event: 'offline',
|
||||||
|
element: document
|
||||||
})
|
})
|
||||||
onDisconnect(): Observable<any> {
|
onDisconnect(): Observable<any> {
|
||||||
return;
|
return;
|
||||||
@ -101,7 +102,8 @@ export class Network extends IonicNativePlugin {
|
|||||||
*/
|
*/
|
||||||
@Cordova({
|
@Cordova({
|
||||||
eventObservable: true,
|
eventObservable: true,
|
||||||
event: 'online'
|
event: 'online',
|
||||||
|
element: document
|
||||||
})
|
})
|
||||||
onConnect(): Observable<any> {
|
onConnect(): Observable<any> {
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user