react_hsbc_teller 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +4 -0
- package/README.en.md +36 -0
- package/README.md +57 -0
- package/config/webpack.config.js +114 -0
- package/config/webpack.dev.js +108 -0
- package/config/webpack.prod.js +113 -0
- package/package.json +94 -0
- package/packages/api/api.js +135 -0
- package/packages/api/server.js +48 -0
- package/packages/assets/img/Face_recognition.png +0 -0
- package/packages/assets/img/Projection_screen.png +0 -0
- package/packages/assets/img/huazhonghua.png +0 -0
- package/packages/assets/img/icon_Graffiti.png +0 -0
- package/packages/assets/img/icon_Mute.png +0 -0
- package/packages/assets/img/icon_MuteOne.png +0 -0
- package/packages/assets/img/icon_camera.png +0 -0
- package/packages/assets/img/icon_cameraOne.png +0 -0
- package/packages/assets/img/icon_copy.png +0 -0
- package/packages/assets/img/icon_invitation.png +0 -0
- package/packages/assets/img/icon_ocr.png +0 -0
- package/packages/assets/img/icon_suspend.png +0 -0
- package/packages/assets/img/sign_out.png +0 -0
- package/packages/assets/img/yingpin.png +0 -0
- package/packages/assets/img/zanTing.png +0 -0
- package/packages/assets/pdf/1.png +0 -0
- package/packages/assets/pdf/2.png +0 -0
- package/packages/assets/pdf/3.png +0 -0
- package/packages/assets/pdf/4.png +0 -0
- package/packages/assets/pdf/5.png +0 -0
- package/packages/assets/pdf/6.png +0 -0
- package/packages/common/JKL.js +61 -0
- package/packages/common/XML.js +271 -0
- package/packages/common/websocket.js +246 -0
- package/packages/demo/demo.js +27 -0
- package/packages/demo/index.js +3 -0
- package/packages/envconfig/envconfig.js +13 -0
- package/packages/index.js +2 -0
- package/packages/pages/foot/foot.jsx +101 -0
- package/packages/pages/foot/foot.less +49 -0
- package/packages/pages/header/header.jsx +25 -0
- package/packages/pages/header/header.less +52 -0
- package/packages/pages/pdf/pdf.jsx +72 -0
- package/packages/pages/pdf/pdf.less +18 -0
- package/packages/pages/video/video.jsx +1317 -0
- package/packages/pages/video/video.less +97 -0
- package/packages/style/index.less +1 -0
- package/packages/style/reset.less +345 -0
- package/packages/utils/asyncComponent.jsx +27 -0
- package/packages/utils/cell.js +64 -0
- package/packages/utils/mixin.js +27 -0
- package/packages/utils/setRem.js +11 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +40 -0
- package/public/snowman.svg +1 -0
- package/script.js +0 -0
- package/src/index.js +10 -0
- package/src/index.less +1 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import envconfig from '../envconfig/envconfig';
|
|
3
|
+
/**
|
|
4
|
+
* 主要params参数
|
|
5
|
+
* @params method {string} 方法名
|
|
6
|
+
* @params url {string} 请求地址 例如:/login 配合baseURL组成完整请求地址
|
|
7
|
+
* @params baseURL {string} 请求地址统一前缀 ***需要提前指定*** 例如:http://cangdu.org
|
|
8
|
+
* @params timeout {number} 请求超时时间 默认 30000
|
|
9
|
+
* @params params {object} get方式传参key值
|
|
10
|
+
* @params headers {string} 指定请求头信息
|
|
11
|
+
* @params withCredentials {boolean} 请求是否携带本地cookies信息默认开启
|
|
12
|
+
* @params validateStatus {func} 默认判断请求成功的范围 200 - 300
|
|
13
|
+
* @return {Promise}
|
|
14
|
+
* 其他更多拓展参看axios文档后 自行拓展
|
|
15
|
+
* 注意:params中的数据会覆盖method url 参数,所以如果指定了这2个参数则不需要在params中带入
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export default class Server {
|
|
19
|
+
axios(method, url, params){
|
|
20
|
+
console.log(params)
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
if(typeof params !== 'object') params = {};
|
|
23
|
+
let _option = params;
|
|
24
|
+
_option = {
|
|
25
|
+
method,
|
|
26
|
+
url,
|
|
27
|
+
baseURL: envconfig.baseURL,
|
|
28
|
+
timeout: 30000,
|
|
29
|
+
params: null,
|
|
30
|
+
data: params,
|
|
31
|
+
headers: null,
|
|
32
|
+
withCredentials: true, //是否携带cookies发起请求
|
|
33
|
+
validateStatus:(status)=>{
|
|
34
|
+
return status >= 200 && status < 300;
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
axios.request(_option).then(res => {
|
|
38
|
+
resolve(typeof res.data === 'object' ? res.data : JSON.parse(res.data))
|
|
39
|
+
},error => {
|
|
40
|
+
if(error.response){
|
|
41
|
+
reject(error.response.data)
|
|
42
|
+
}else{
|
|
43
|
+
reject(error)
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const JKL = {};
|
|
2
|
+
|
|
3
|
+
JKL.Dumper = function () {
|
|
4
|
+
return this;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// Dump the data into JSON format
|
|
8
|
+
|
|
9
|
+
JKL.Dumper.prototype.dump = function (data, offset) {
|
|
10
|
+
if (typeof (offset) === 'undefined') offset = '';
|
|
11
|
+
const nextoff = `${offset} `;
|
|
12
|
+
switch (typeof (data)) {
|
|
13
|
+
case 'string':
|
|
14
|
+
return `"${this.escapeString(data)}"`;
|
|
15
|
+
break;
|
|
16
|
+
case 'number':
|
|
17
|
+
return data;
|
|
18
|
+
break;
|
|
19
|
+
case 'boolean':
|
|
20
|
+
return data ? 'true' : 'false';
|
|
21
|
+
break;
|
|
22
|
+
case 'undefined':
|
|
23
|
+
return 'null';
|
|
24
|
+
break;
|
|
25
|
+
case 'object':
|
|
26
|
+
if (data == null) {
|
|
27
|
+
return 'null';
|
|
28
|
+
} if (data.constructor == Array) {
|
|
29
|
+
var array = [];
|
|
30
|
+
for (let i = 0; i < data.length; i++) {
|
|
31
|
+
array[i] = this.dump(data[i], nextoff);
|
|
32
|
+
}
|
|
33
|
+
return `[\n${nextoff}${array.join(`,\n${nextoff}`)}\n${offset}]`;
|
|
34
|
+
}
|
|
35
|
+
var array = [];
|
|
36
|
+
for (let key in data) {
|
|
37
|
+
const val = this.dump(data[key], nextoff);
|
|
38
|
+
// if ( key.match( /[^A-Za-z0-9_]/ )) {
|
|
39
|
+
key = `"${this.escapeString(key)}"`;
|
|
40
|
+
// }
|
|
41
|
+
array[array.length] = `${key}: ${val}`;
|
|
42
|
+
}
|
|
43
|
+
if (array.length == 1 && !array[0].match(/[\n\{\[]/)) {
|
|
44
|
+
return `{ ${array[0]} }`;
|
|
45
|
+
}
|
|
46
|
+
return `{\n${nextoff}${array.join(`,\n${nextoff}`)}\n${offset}}`;
|
|
47
|
+
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
return data;
|
|
51
|
+
// unsupported data type
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// escape '\' and '"'
|
|
57
|
+
|
|
58
|
+
JKL.Dumper.prototype.escapeString = function (str) {
|
|
59
|
+
return str.replace(/\\/g, '\\\\').replace(/\"/g, '\\"');
|
|
60
|
+
};
|
|
61
|
+
export default JKL;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
// ========================================================================
|
|
3
|
+
// XML.ObjTree -- XML source code from/to JavaScript object like E4X
|
|
4
|
+
// ========================================================================
|
|
5
|
+
|
|
6
|
+
import JKL from './JKL';
|
|
7
|
+
|
|
8
|
+
const XML = {};
|
|
9
|
+
|
|
10
|
+
XML.ObjTree = function () {
|
|
11
|
+
return this;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// class variables
|
|
15
|
+
|
|
16
|
+
XML.ObjTree.VERSION = '0.23';
|
|
17
|
+
|
|
18
|
+
// object prototype
|
|
19
|
+
|
|
20
|
+
XML.ObjTree.prototype.xmlDecl = '<?xml version="1.0" encoding="UTF-8" ?>\n';
|
|
21
|
+
XML.ObjTree.prototype.attr_prefix = '-';
|
|
22
|
+
|
|
23
|
+
// method: parseXML( xmlsource )
|
|
24
|
+
|
|
25
|
+
XML.ObjTree.prototype.parseXML = function (xml) {
|
|
26
|
+
let xmldom;
|
|
27
|
+
let root;
|
|
28
|
+
if (window.DOMParser) {
|
|
29
|
+
xmldom = new DOMParser();
|
|
30
|
+
// xmldom.async = false; // DOMParser is always sync-mode
|
|
31
|
+
const dom = xmldom.parseFromString(xml, 'application/xml');
|
|
32
|
+
if (!dom) return;
|
|
33
|
+
root = dom.documentElement;
|
|
34
|
+
} else if (window.ActiveXObject) {
|
|
35
|
+
xmldom = new ActiveXObject('Microsoft.XMLDOM');
|
|
36
|
+
xmldom.async = false;
|
|
37
|
+
xmldom.loadXML(xml);
|
|
38
|
+
root = xmldom.documentElement;
|
|
39
|
+
}
|
|
40
|
+
if (!root) return;
|
|
41
|
+
return this.parseDOM(root);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// method: parseHTTP( url, options, callback )
|
|
45
|
+
|
|
46
|
+
XML.ObjTree.prototype.parseHTTP = function (url, options, callback) {
|
|
47
|
+
const myopt = {};
|
|
48
|
+
for (const key in options) {
|
|
49
|
+
myopt[key] = options[key]; // copy object
|
|
50
|
+
}
|
|
51
|
+
if (!myopt.method) {
|
|
52
|
+
if (typeof (myopt.postBody) === 'undefined'
|
|
53
|
+
&& typeof (myopt.postbody) === 'undefined'
|
|
54
|
+
&& typeof (myopt.parameters) === 'undefined') {
|
|
55
|
+
myopt.method = 'get';
|
|
56
|
+
} else {
|
|
57
|
+
myopt.method = 'post';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (callback) {
|
|
61
|
+
myopt.asynchronous = true; // async-mode
|
|
62
|
+
const __this = this;
|
|
63
|
+
const __func = callback;
|
|
64
|
+
const __save = myopt.onComplete;
|
|
65
|
+
myopt.onComplete = function (trans) {
|
|
66
|
+
let tree;
|
|
67
|
+
if (trans && trans.responseXML && trans.responseXML.documentElement) {
|
|
68
|
+
tree = __this.parseDOM(trans.responseXML.documentElement);
|
|
69
|
+
}
|
|
70
|
+
__func(tree, trans);
|
|
71
|
+
if (__save) __save(trans);
|
|
72
|
+
};
|
|
73
|
+
} else {
|
|
74
|
+
myopt.asynchronous = false; // sync-mode
|
|
75
|
+
}
|
|
76
|
+
let trans;
|
|
77
|
+
if (typeof (HTTP) !== 'undefined' && HTTP.Request) {
|
|
78
|
+
myopt.uri = url;
|
|
79
|
+
var req = new HTTP.Request(myopt); // JSAN
|
|
80
|
+
if (req) trans = req.transport;
|
|
81
|
+
} else if (typeof (Ajax) !== 'undefined' && Ajax.Request) {
|
|
82
|
+
var req = new Ajax.Request(url, myopt); // ptorotype.js
|
|
83
|
+
if (req) trans = req.transport;
|
|
84
|
+
}
|
|
85
|
+
if (callback) return trans;
|
|
86
|
+
if (trans && trans.responseXML && trans.responseXML.documentElement) {
|
|
87
|
+
return this.parseDOM(trans.responseXML.documentElement);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// method: parseDOM( documentroot )
|
|
92
|
+
|
|
93
|
+
XML.ObjTree.prototype.parseDOM = function (root) {
|
|
94
|
+
if (!root) return;
|
|
95
|
+
|
|
96
|
+
this.__force_array = {};
|
|
97
|
+
if (this.force_array) {
|
|
98
|
+
for (let i = 0; i < this.force_array.length; i++) {
|
|
99
|
+
this.__force_array[this.force_array[i]] = 1;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let json = this.parseElement(root); // parse root node
|
|
104
|
+
if (this.__force_array[root.nodeName]) {
|
|
105
|
+
json = [json];
|
|
106
|
+
}
|
|
107
|
+
if (root.nodeType != 11) { // DOCUMENT_FRAGMENT_NODE
|
|
108
|
+
const tmp = {};
|
|
109
|
+
tmp[root.nodeName] = json; // root nodeName
|
|
110
|
+
json = tmp;
|
|
111
|
+
}
|
|
112
|
+
return json;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// method: parseElement( element )
|
|
116
|
+
|
|
117
|
+
XML.ObjTree.prototype.parseElement = function (elem) {
|
|
118
|
+
// COMMENT_NODE
|
|
119
|
+
if (elem.nodeType == 7) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// TEXT_NODE CDATA_SECTION_NODE
|
|
124
|
+
if (elem.nodeType == 3 || elem.nodeType == 4) {
|
|
125
|
+
const bool = elem.nodeValue.match(/[^\x00-\x20]/);
|
|
126
|
+
if (bool == null) return; // ignore white spaces
|
|
127
|
+
return elem.nodeValue;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let retval;
|
|
131
|
+
const cnt = {};
|
|
132
|
+
|
|
133
|
+
// parse attributes
|
|
134
|
+
if (elem.attributes && elem.attributes.length) {
|
|
135
|
+
retval = {};
|
|
136
|
+
for (var i = 0; i < elem.attributes.length; i++) {
|
|
137
|
+
var key = elem.attributes[i].nodeName;
|
|
138
|
+
if (typeof (key) !== 'string') continue;
|
|
139
|
+
var val = elem.attributes[i].nodeValue;
|
|
140
|
+
if (!val) continue;
|
|
141
|
+
key = this.attr_prefix + key;
|
|
142
|
+
if (typeof (cnt[key]) === 'undefined') cnt[key] = 0;
|
|
143
|
+
cnt[key]++;
|
|
144
|
+
this.addNode(retval, key, cnt[key], val);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// parse child nodes (recursive)
|
|
149
|
+
if (elem.childNodes && elem.childNodes.length) {
|
|
150
|
+
let textonly = true;
|
|
151
|
+
if (retval) textonly = false; // some attributes exists
|
|
152
|
+
for (var i = 0; i < elem.childNodes.length && textonly; i++) {
|
|
153
|
+
const ntype = elem.childNodes[i].nodeType;
|
|
154
|
+
if (ntype == 3 || ntype == 4) continue;
|
|
155
|
+
textonly = false;
|
|
156
|
+
}
|
|
157
|
+
if (textonly) {
|
|
158
|
+
if (!retval) retval = '';
|
|
159
|
+
for (var i = 0; i < elem.childNodes.length; i++) {
|
|
160
|
+
retval += elem.childNodes[i].nodeValue;
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
if (!retval) retval = {};
|
|
164
|
+
for (var i = 0; i < elem.childNodes.length; i++) {
|
|
165
|
+
var key = elem.childNodes[i].nodeName;
|
|
166
|
+
if (typeof (key) !== 'string') continue;
|
|
167
|
+
var val = this.parseElement(elem.childNodes[i]);
|
|
168
|
+
if (!val) continue;
|
|
169
|
+
if (typeof (cnt[key]) === 'undefined') cnt[key] = 0;
|
|
170
|
+
cnt[key]++;
|
|
171
|
+
this.addNode(retval, key, cnt[key], val);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return retval;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// method: addNode( hash, key, count, value )
|
|
179
|
+
|
|
180
|
+
XML.ObjTree.prototype.addNode = function (hash, key, cnts, val) {
|
|
181
|
+
if (this.__force_array[key]) {
|
|
182
|
+
if (cnts == 1) hash[key] = [];
|
|
183
|
+
hash[key][hash[key].length] = val; // push
|
|
184
|
+
} else if (cnts == 1) { // 1st sibling
|
|
185
|
+
hash[key] = val;
|
|
186
|
+
} else if (cnts == 2) { // 2nd sibling
|
|
187
|
+
hash[key] = [hash[key], val];
|
|
188
|
+
} else { // 3rd sibling and more
|
|
189
|
+
hash[key][hash[key].length] = val;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// method: writeXML( tree )
|
|
194
|
+
|
|
195
|
+
XML.ObjTree.prototype.writeXML = function (tree) {
|
|
196
|
+
const xml = this.hash_to_xml(null, tree);
|
|
197
|
+
return this.xmlDecl + xml;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// method: hash_to_xml( tagName, tree )
|
|
201
|
+
|
|
202
|
+
XML.ObjTree.prototype.hash_to_xml = function (name, tree) {
|
|
203
|
+
const elem = [];
|
|
204
|
+
const attr = [];
|
|
205
|
+
for (const key in tree) {
|
|
206
|
+
if (!tree.hasOwnProperty(key)) continue;
|
|
207
|
+
const val = tree[key];
|
|
208
|
+
if (key.charAt(0) != this.attr_prefix) {
|
|
209
|
+
if (typeof (val) === 'undefined' || val == null) {
|
|
210
|
+
elem[elem.length] = `<${key} />`;
|
|
211
|
+
} else if (typeof (val) === 'object' && val.constructor == Array) {
|
|
212
|
+
elem[elem.length] = this.array_to_xml(key, val);
|
|
213
|
+
} else if (typeof (val) === 'object') {
|
|
214
|
+
elem[elem.length] = this.hash_to_xml(key, val);
|
|
215
|
+
} else {
|
|
216
|
+
elem[elem.length] = this.scalar_to_xml(key, val);
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
attr[attr.length] = ` ${key.substring(1)}="${this.xml_escape(val)}"`;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const jattr = attr.join('');
|
|
223
|
+
let jelem = elem.join('');
|
|
224
|
+
if (typeof (name) === 'undefined' || name == null) {
|
|
225
|
+
// no tag
|
|
226
|
+
} else if (elem.length > 0) {
|
|
227
|
+
if (jelem.match(/\n/)) {
|
|
228
|
+
jelem = `<${name}${jattr}>\n${jelem}</${name}>\n`;
|
|
229
|
+
} else {
|
|
230
|
+
jelem = `<${name}${jattr}>${jelem}</${name}>\n`;
|
|
231
|
+
}
|
|
232
|
+
} else {
|
|
233
|
+
jelem = `<${name}${jattr} />\n`;
|
|
234
|
+
}
|
|
235
|
+
return jelem;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// method: array_to_xml( tagName, array )
|
|
239
|
+
|
|
240
|
+
XML.ObjTree.prototype.array_to_xml = function (name, array) {
|
|
241
|
+
const out = [];
|
|
242
|
+
for (let i = 0; i < array.length; i++) {
|
|
243
|
+
const val = array[i];
|
|
244
|
+
if (typeof (val) === 'undefined' || val == null) {
|
|
245
|
+
out[out.length] = `<${name} />`;
|
|
246
|
+
} else if (typeof (val) === 'object' && val.constructor == Array) {
|
|
247
|
+
out[out.length] = this.array_to_xml(name, val);
|
|
248
|
+
} else if (typeof (val) === 'object') {
|
|
249
|
+
out[out.length] = this.hash_to_xml(name, val);
|
|
250
|
+
} else {
|
|
251
|
+
out[out.length] = this.scalar_to_xml(name, val);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return out.join('');
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// method: scalar_to_xml( tagName, text )
|
|
258
|
+
|
|
259
|
+
XML.ObjTree.prototype.scalar_to_xml = function (name, text) {
|
|
260
|
+
if (name == '#text') {
|
|
261
|
+
return this.xml_escape(text);
|
|
262
|
+
}
|
|
263
|
+
return `<${name}>${this.xml_escape(text)}</${name}>\n`;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
// method: xml_escape( text )
|
|
267
|
+
|
|
268
|
+
XML.ObjTree.prototype.xml_escape = function (text) {
|
|
269
|
+
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
270
|
+
};
|
|
271
|
+
export default XML;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import XML from './XML';
|
|
2
|
+
import JKL from './JKL';
|
|
3
|
+
|
|
4
|
+
let websock;
|
|
5
|
+
let id;
|
|
6
|
+
const xmlLang = 'zh';
|
|
7
|
+
const version = '1.0';
|
|
8
|
+
let islogin = false;
|
|
9
|
+
export default function initWebSocket(wsuri) {
|
|
10
|
+
// eslint-disable-next-line no-undef
|
|
11
|
+
websock = new WebSocket(wsuri, 'xmpp');
|
|
12
|
+
websock.onmessage = websocketonmessage;
|
|
13
|
+
websock.onopen = websocketonopen;
|
|
14
|
+
websock.onerror = websocketonerror;
|
|
15
|
+
websock.onclose = websocketclose;
|
|
16
|
+
}
|
|
17
|
+
const connectionState = ['正在连接..', '连接已建立', '正在关闭..', '已经关闭'];
|
|
18
|
+
// json转xml
|
|
19
|
+
function json2xml(jsonstring) {
|
|
20
|
+
const xotree = new XML.ObjTree();
|
|
21
|
+
const xml = xotree.writeXML(jsonstring);
|
|
22
|
+
return xml;
|
|
23
|
+
}
|
|
24
|
+
// xml转json
|
|
25
|
+
function xml2json(xmlstring) {
|
|
26
|
+
// 将xml字符串转为json
|
|
27
|
+
const xotree = new XML.ObjTree();
|
|
28
|
+
const json = xotree.parseXML(xmlstring);
|
|
29
|
+
// 将json对象转为格式化的字符串
|
|
30
|
+
const dumper = new JKL.Dumper();
|
|
31
|
+
const jsonText = dumper.dump(json);
|
|
32
|
+
return JSON.parse(jsonText);
|
|
33
|
+
}
|
|
34
|
+
function websocketonopen() { // 连接建立之后执行send方法发送数据
|
|
35
|
+
console.log('成功');
|
|
36
|
+
// 发送建立流请求
|
|
37
|
+
const steam = {
|
|
38
|
+
open: {
|
|
39
|
+
'-to': JSON.parse(window.sessionStorage.getItem('sigData')).hostname,
|
|
40
|
+
'-from': `${JSON.parse(window.sessionStorage.getItem('sigData')).account}@${JSON.parse(window.sessionStorage.getItem('sigData')).hostname}`,
|
|
41
|
+
'-xmlns': 'urn:ietf:params:xml:ns:xmpp-framing',
|
|
42
|
+
'-xml:lang': xmlLang,
|
|
43
|
+
'-version': version,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
websocketsend(json2xml(steam));
|
|
47
|
+
}
|
|
48
|
+
function websocketonerror() { // 连接建立失败重连
|
|
49
|
+
window.IMOpenfire('false');
|
|
50
|
+
console.log('失败');
|
|
51
|
+
// initWebSocket()
|
|
52
|
+
}
|
|
53
|
+
function websocketonmessage(e) {
|
|
54
|
+
console.log('收到消息', e);
|
|
55
|
+
console.log('收到消息', e.data);
|
|
56
|
+
const jsondata = xml2json(e.data);
|
|
57
|
+
console.log('jsondata', jsondata);
|
|
58
|
+
if (undefined != jsondata.message) {
|
|
59
|
+
if (undefined != jsondata.message.body) {
|
|
60
|
+
console.log('收到的消息:', jsondata.message.body);
|
|
61
|
+
const from = jsondata.message['-from'];
|
|
62
|
+
console.log('from', from);
|
|
63
|
+
const type = jsondata.message['-type'];
|
|
64
|
+
console.log('type', type);
|
|
65
|
+
if ((from.split('/').length > 0) && (from.split('/')[from.split('/').length - 1] == JSON.parse(window.sessionStorage.getItem('sigData')).account)) {
|
|
66
|
+
// 自己的消息不做处理
|
|
67
|
+
} else if ((type == 'chat' || type == 'groupchat') && jsondata.message.body.length > 0) {
|
|
68
|
+
// console.log('message', (jsondata.message.body.indexOf("IMVedio") != -1))
|
|
69
|
+
// if (jsondata.message.body.indexOf("IMVedio") != -1) {
|
|
70
|
+
// window.VedioEvt(jsondata.message.body)
|
|
71
|
+
// } else {
|
|
72
|
+
window.IMEvt(jsondata.message.body);
|
|
73
|
+
// }
|
|
74
|
+
}
|
|
75
|
+
} else if (undefined != jsondata.message.composing) {
|
|
76
|
+
console.log('对方正在输入');
|
|
77
|
+
} else if (undefined != jsondata.message.gone) {
|
|
78
|
+
console.log('对方已关闭和您的聊天');
|
|
79
|
+
} else if (undefined != jsondata.message.file) {
|
|
80
|
+
console.log('收到的文件:', jsondata.message);
|
|
81
|
+
} else {
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
} else if (undefined != jsondata.open) {
|
|
85
|
+
// 记录id
|
|
86
|
+
id = jsondata.open['-id'];
|
|
87
|
+
console.log(id);
|
|
88
|
+
} else if (undefined != jsondata['stream:features']) {
|
|
89
|
+
if (undefined != jsondata['stream:features'].mechanisms) {
|
|
90
|
+
// 获取登录验证方式
|
|
91
|
+
auth(jsondata['stream:features'].mechanisms.mechanism[0]);
|
|
92
|
+
} else if (undefined != jsondata['stream:features'].bind) {
|
|
93
|
+
bind();
|
|
94
|
+
} else {
|
|
95
|
+
// Do-nothing
|
|
96
|
+
}
|
|
97
|
+
} else if (undefined != jsondata.failure) {
|
|
98
|
+
islogin = false;
|
|
99
|
+
console.log('登录失败,用户名或者密码错误');
|
|
100
|
+
window.IMOpenfire('false');
|
|
101
|
+
} else if (undefined != jsondata.success) {
|
|
102
|
+
islogin = true;
|
|
103
|
+
console.log('登录成功!');
|
|
104
|
+
// 发起新的流
|
|
105
|
+
newopen();
|
|
106
|
+
} else if (undefined != jsondata.iq) {
|
|
107
|
+
if (undefined != jsondata.iq.bind) {
|
|
108
|
+
// 获取session会话
|
|
109
|
+
getsession();
|
|
110
|
+
} else {
|
|
111
|
+
presence();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// 结束状态
|
|
116
|
+
function disconnect() {
|
|
117
|
+
const temp = {
|
|
118
|
+
close: {
|
|
119
|
+
'-xmlns': 'urn:ietf:params:xml:ns:xmpp-framing',
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
// 转化为xml
|
|
123
|
+
websocketsend(json2xml(temp));
|
|
124
|
+
}
|
|
125
|
+
// 获取session
|
|
126
|
+
function getsession() {
|
|
127
|
+
// <iq xmlns="jabber:client" id="ak014gz6x7" type="set"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>
|
|
128
|
+
const temp = {
|
|
129
|
+
iq: {
|
|
130
|
+
'-xmlns': 'jabber:client',
|
|
131
|
+
'-id': id,
|
|
132
|
+
'-type': 'set',
|
|
133
|
+
session: {
|
|
134
|
+
'-xmlns': 'urn:ietf:params:xml:ns:xmpp-session',
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
// 转化为xml
|
|
139
|
+
websocketsend(json2xml(temp));
|
|
140
|
+
}
|
|
141
|
+
// 上线
|
|
142
|
+
function presence() {
|
|
143
|
+
// <presence id="ak014gz6x7"><status>Online</status><priority>1</priority></presence>
|
|
144
|
+
const temp = {
|
|
145
|
+
presence: {
|
|
146
|
+
'-id': id,
|
|
147
|
+
status: 'online',
|
|
148
|
+
priority: '1',
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
// 转化为xml
|
|
152
|
+
websocketsend(json2xml(temp));
|
|
153
|
+
}
|
|
154
|
+
// 发起新的流
|
|
155
|
+
function newopen() {
|
|
156
|
+
const temp = {
|
|
157
|
+
open: {
|
|
158
|
+
'-xmlns': 'jabber:client',
|
|
159
|
+
'-to': JSON.parse(window.sessionStorage.getItem('sigData')).hostname,
|
|
160
|
+
'-version': version,
|
|
161
|
+
'-from': `${JSON.parse(window.sessionStorage.getItem('sigData')).account}@${JSON.parse(window.sessionStorage.getItem('sigData')).hostname}`,
|
|
162
|
+
'-id': id,
|
|
163
|
+
'-xml:lang': xmlLang,
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
// 转化为xml
|
|
167
|
+
websocketsend(json2xml(temp));
|
|
168
|
+
}
|
|
169
|
+
// bind操作
|
|
170
|
+
function bind() {
|
|
171
|
+
const temp = {
|
|
172
|
+
iq: {
|
|
173
|
+
'-id': id,
|
|
174
|
+
'-type': 'set',
|
|
175
|
+
bind: {
|
|
176
|
+
'-xmlns': 'urn:ietf:params:xml:ns:xmpp-bind',
|
|
177
|
+
resource: 'appClient',
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
websocketsend(json2xml(temp));
|
|
182
|
+
}
|
|
183
|
+
function auth(val) {
|
|
184
|
+
// Base64编码
|
|
185
|
+
console.log('www');
|
|
186
|
+
const token = window.btoa(`${JSON.parse(window.sessionStorage.getItem('sigData')).account}@${JSON.parse(window.sessionStorage.getItem('sigData')).hostname}\0` + '111111');
|
|
187
|
+
const message = {
|
|
188
|
+
auth: {
|
|
189
|
+
'-xmlns': 'urn:ietf:params:xml:ns:xmpp-sasl',
|
|
190
|
+
'-mechanism': val,
|
|
191
|
+
'#text': token,
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
console.log(`Client: ${message}`);
|
|
195
|
+
websocketsend(json2xml(message));
|
|
196
|
+
}
|
|
197
|
+
function websocketsend(Data) { // 数据发送
|
|
198
|
+
console.log('data', Data);
|
|
199
|
+
websock.send(Data);
|
|
200
|
+
}
|
|
201
|
+
function websocketclose(e) { // 关闭
|
|
202
|
+
console.log('断开连接', e);
|
|
203
|
+
// window.IMOpenfire('false')
|
|
204
|
+
}
|
|
205
|
+
// 发消息
|
|
206
|
+
// // 发送消息 to---接收者id,from---发送者id,type---消息类型(chat--单聊,groupchat--群聊)。message--发送的消息
|
|
207
|
+
function sendMessage(to, from, type, message) {
|
|
208
|
+
console.log('发送聊天信息', to, from, type, message);
|
|
209
|
+
if (islogin) {
|
|
210
|
+
const temp = {
|
|
211
|
+
message: {
|
|
212
|
+
'-type': type,
|
|
213
|
+
'-from': from,
|
|
214
|
+
'-to': to,
|
|
215
|
+
subject: '标题',
|
|
216
|
+
body: message,
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
// 转化为xml
|
|
220
|
+
websocketsend(json2xml(temp));
|
|
221
|
+
} else {
|
|
222
|
+
alert('请先登录!');
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// 加入群 from---加入群的人的jid,to--群名称
|
|
226
|
+
function joinRoom(from, to) {
|
|
227
|
+
// 发送<presence>元素,加入房间
|
|
228
|
+
console.log('from', from);
|
|
229
|
+
console.log('to', to);
|
|
230
|
+
if (islogin) {
|
|
231
|
+
const temp = {
|
|
232
|
+
presence: {
|
|
233
|
+
'-from': from,
|
|
234
|
+
'-id': id,
|
|
235
|
+
'-to': `${to}/${from.substring(0, from.indexOf('@'))}`,
|
|
236
|
+
x: {
|
|
237
|
+
'-xmlns': 'http://jabber.org/protocol/muc',
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
// 转化为xml
|
|
242
|
+
websocketsend(json2xml(temp));
|
|
243
|
+
} else {
|
|
244
|
+
alert('请先登录!');
|
|
245
|
+
}
|
|
246
|
+
}
|