我正在使用带有ionic 3的firebase开发聊天应用程序。当断开与互联网的连接时,我必须将状态更改为“离线”。
我提到了以下网站:
1)https://firebase.google.com/docs/database/web/offline-capabilities
2)https://firebase.google.com/docs/reference/js/firebase.database.OnDisconnect
getDetails(formData){
let headers = new HttpHeaders()
return this.http.post(this.domain + 'authentication/register',
formData).map(res =>res)
}
当我关闭互联网连接时,this.disconnectSubscription = this.network
.onDisconnect()
.subscribe(() => {
this.online = false;
var userLastOnlineRef = firebase.database().ref('/accounts/'this.loggedInUserId);
userLastOnlineRef.onDisconnect().set({status:offline});
});
的状态将不会更改。
答案 0 :(得分:1)
您可以像这样收听在线和离线事件
window.addEventListener("online", this.doSomethingWhenOnline);
window.addEventListener("offline", this.doSomethingWhenOffline);
doSomethingWhenOnline() {
}
doSomethingWhenOffline() {
}