-
-
Save cionman/738677ca395626a5eafdcce809104a86 to your computer and use it in GitHub Desktop.
온라인 여부 체크
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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