-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
83 lines (75 loc) · 1.92 KB
/
index.html
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
<html>
<head>
<title>[test sproto ]</title>
<script type="text/javascript" src="./Sproto.js"></script>
</head>
<body>
<script>
function arr2ab(array) {
var len = array.length;
var b = new ArrayBuffer(len + 2);
var v = new DataView(b, 0);
v.setUint16(0,len);
for (var i = 0; i < array.length; i++) {
v.setUint8(i + 2, array[i]);
}
return b;
}
function ab2arr(buffer) {
var v = new DataView(buffer, 0);
var a = new Array();
var len = v.getUint16(0);
for (var i = 0; i < len; i++) {
a[i] = v.getUint8(i+2);
}
return a;
}
var c2s
var s2c
var session
function init_sproto(map){
console.log("init_sproto")
s2c = Sproto.new(map['./s2c.sp']);
c2s = Sproto.new(map['./c2s.sp']);
c2s.host("package");
host = s2c.host("package");
request = host.attach(c2s);
session = session + 1;
var p = request("handshake", null, session).buf;
var d = arr2ab(p);
//socket.send(d)
}
function getSpFiles(filenames,cb){
function getFile(filename,callback){
var xhr = new XMLHttpRequest();
xhr.open('GET', filename, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function(e) {
var buff = xhr.response;
var dataview = new DataView(buff);
var schema = new Array();
for (var i = 0; i < dataview.byteLength; i++) {
schema[i] = dataview.getUint8(i);
}
//alert(dataview.byteLength);
callback(filename,{buf:schema, sz:schema.length});
};
xhr.send();
}
for(i = 0;i < filenames.length;i++){
getFile(filenames[i],cb)
}
}
getSpFiles(['./c2s.sp','./s2c.sp'],loaded_callbac);
var loadedMap = {len : 0};
function loaded_callbac(filename,data) {
loadedMap.len ++;
var obj = {}
loadedMap[filename] = data
if(loadedMap.len == 2 ){
init_sproto(loadedMap);
}
}
</script>
</body>
</html>