Observe Cordova Network Connection Events with rxjs

is it somehow possible to make an rxjs observable with the fromEvent method out of the cordova network connection plugin.

i am trying that with ionic 2.

i can see, that there are two events (online/offline) in the cordova network connection plugin. but how to hook into them with rxjs?

something that looks like that:

const offline$ = Observable.fromEvent(CORDOVA_OFFLINE_EVENT);
offline$.subscribe(
    function (connectionType) {
        console.log("connectionType", JSON.stringify(connectionType));
    },
    function (err) {
        console.log('Error: ' + err);
    },
    function () {
        console.log('Completed');
    }
);

i also created a stackoverflow question

1 Like