forked from ShukriChiu/webrtc.chatdemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatLib.js
60 lines (50 loc) · 1.3 KB
/
chatLib.js
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
(function(exports) {
// 事件类型
exports.EVENT_TYPE = {
'LOGIN': 'LOGIN',
'LOGOUT': 'LOGOUT',
'SPEAK': 'SPEAK',
'LIST_USER': 'LIST_USER',
'ERROR': 'ERROR',
'LIST_HISTORY': 'LIST_HISTORY'
};
// 服务端口
exports.PORT = 8000;
// 服务端口
// need to alter to your ip adress
exports.HOST = "localhost";
var analyzeMessageData = exports.analyzeMessageData = function(message) {
try {
return JSON.parse(message);
} catch(error) {
// 收到了非正常格式的数据
console.log('method:analyzeMsgData,error:' + error);
}
return null;
}
var getMsgFirstDataValue = exports.getMsgFirstDataValue = function(mData) {
if(mData && mData.values && mData.values[0]) {
return mData.values[0];
}
return '';
}
var getMsgSecondDataValue = exports.getMsgSecondDataValue = function(mData) {
if(mData && mData.values && mData.values[1]) {
return mData.values[1];
}
return '';
}
var getMsgThirdDataValue = exports.getMsgThirdDataValue = function(mData) {
if(mData && mData.values && mData.values[2]) {
return mData.values[2];
}
return '';
}
})((function() {
if(typeof exports === 'undefined') {
window.chatLib = {};
return window.chatLib;
} else {
return exports;
}
})());