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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
$.support.cors = true;
 
/**
 * url: 特定功能的Url,如:/Login_webSdkAuth.action
 * callback: 回调函数 
 * requestType: The type of request
 * to make ("POST" or "GET"), default is "POST". 
 * requestJson: 请求参数
 */
function chatRequest(url, requestType, requestJson, callback) {
    if (requestType == null)
        requestType = "POST";
 
    var headers;
    var contentType;
    var requestData;
    
    if (requestType == "POST" || requestType == "PUT"){
        contentType = "application/json;charset=UTF-8";
        requestData = JSON.stringify(requestJson);
    } else {
        requestData = requestJson;
    }
    
    var headerJson = {};
    if (getServerKey()){
        headerJson.serverKey = getServerKey();
    }
    
    if (getApiKey()){
        headerJson.apiKey = getApiKey();
    }
    console.log(callback)
    if (callback) { // async call
        $.ajax({
            url : _urlHeadAjax + url,
            async : true,
            crossDomain: true,
            type : requestType,
            data : requestData,
            headers: headerJson,
            cache: false,
            contentType : contentType,
            success : function(responseJson) {
                console.log(responseJson)
                callback(responseJson);
                //showResult(0, responseJson, url + ":");
            },
            error : function(responseJson) {
                //showResult(0, responseJson.responseText, url + " Err:");
            }
        });
    } else { // sync call
        var rst;
        $.ajax({
            url : _urlHeadAjax + url,
            async : false,
            crossDomain: true,
            type : requestType,
            data : requestData,
            headers: headerJson,
            cache: false,
            contentType : contentType,
            success : function(responseJson) {
                console.log(responseJson)
                rst = responseJson;
                //showResult(0, responseJson, url + ":");
            },
            error : function(responseJson) {
                //showResult(0, responseJson.responseText, url + " Err:");
            }
        });
 
        return rst;
    }
}
 
function getServerKey(){
    return sessionStorage.getItem("serverKey");
}
 
function getApiKey(){
    return sessionStorage.getItem("apiKey");;
}
 
function AirSession() {
    this.sessionId = "";
    this.sessionIndex = 0;
    this.sessionState = SESSION_STATE_IDLE;
 
    this.mediaState = MEDIA_STATE_IDLE;
    this.mediaSpeaker = null;
 
    this.lock = 0;
}