zhitong.yu
2024-05-11 b72f8f8d58417eb6fb29672d8ac17cfafa46775c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//=================================================================
//                    API说明
//
// Function:
//
//    - account_event_set_loginout(cbLogin, cbLogout, cbHeartbeat):设置全局本机用户登录登出回调
//    - account_event_set_presence(cbPresence):设置全局用户状态变化回调函数
//
//    - account_login(serverAddr, userId, userPass):本机用户登录系统
//    - account_logout():本机用户登出系统
//
// Event:
//
//    - cbUserLogin(result);        用户登录状态返回
//    - cbUserLogout();            用户登出状态返回
//    - cbUserHeartbeat(result);    用户心跳状态返回
//  - cbUserPresence(json);        用户在线状态
//
//=================================================================
 
 
var cbUserPresence = null;
var cbUserLogin = null;
var cbUserLogout = null;
var cbUserHeartbeat = null;
 
 
/******************************* FUNC ********************************/
 
function account_event_set_loginout(cbLogin, cbLogout, cbHeartbeat) {
    cbUserLogin = cbLogin;
    cbUserLogout = cbLogout;
    cbUserHeartbeat = cbHeartbeat;
}
 
function account_event_set_presence(cbPresence) {
    cbUserPresence = cbPresence;
}
 
function account_login(serverAddr, userId, userPass) {
    doLogin(serverAddr, userId, userPass);
}
 
function account_logout() {
    doLoginOut();
}
 
function account_presence_subscribe(isCustom, json) {
    doPresenceSubscribe(isCustom, json);
}
 
function account_presence_unsubscribe() {
    doPresenceUnsubscribe();
}
 
/******************************* EVENT ********************************/
 
function onLogin(result, secret) {
    if (cbUserLogin != null)
        cbUserLogin(result);
}
 
function onLogout(result) {
    if (cbUserLogout != null)
        cbUserLogout();
}
 
function onHeartbeat(result) {
    if (cbUserHeartbeat != null)
        cbUserHeartbeat(result);
}
 
// user presence
function onContactPresence(json) {
    if (cbUserPresence != null && json != null)
        cbUserPresence(json.sessionmember);
}