Skip to content

Instantly share code, notes, and snippets.

@cionman
Last active December 3, 2017 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cionman/738677ca395626a5eafdcce809104a86 to your computer and use it in GitHub Desktop.
Save cionman/738677ca395626a5eafdcce809104a86 to your computer and use it in GitHub Desktop.
온라인 여부 체크
<script>
/**
* 로그인 후 세팅
*/
FirebaseChat.prototype.setLogin = function(user){ //user 파라미터 추가
//...생략
this.checkOnline();
}
/**
* 온라인 여부 체크 하기 위한 데이터 입력
*/
FirebaseChat.prototype.checkOnline = function(){
var userUid = this.auth.currentUser.uid;
var myConnectionsRef = this.database.ref('UsersConnection/'+userUid+'/connection');
var lastOnlineRef = this.database.ref('UsersConnection/'+userUid+'/lastOnline');
var connectedRef = this.database.ref('.info/connected');
connectedRef.on('value', function(snap) {
if (snap.val() === true) {
myConnectionsRef.set(true);
// 연결 단절 이벤트
myConnectionsRef.onDisconnect().set(false);
lastOnlineRef.onDisconnect().set(firebase.database.ServerValue.TIMESTAMP);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment