-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscaffolding.html
135 lines (115 loc) · 3.46 KB
/
scaffolding.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.slim.js"></script>
<script>
function $_GET(q,s) {
if(window.location.search == '') return undefined;
s = s ? s : window.location.search;
var re = new RegExp('&'+q+'(?:=([^&]*))?(?=&|$)','i');
return (s=s.replace(/^\?/,'&').match(re)) ? (typeof s[1] == 'undefined' ? '' : decodeURIComponent(s[1])) : undefined;
}
var messageId = 0;
var socketUri = 'ws://localhost:9990';
var callCount = 0;
var socket;
function log(response) {
console.log(response);
errors.innerHTML = 'No Errors';
if(response.success && response.success == false) errors.innerHTML = response.text;
}
function submitLogin() {
var data = {
username: document.getElementById('api_username').value,
password: document.getElementById('api_passcode').value
};
socket.emit('auth.login', data);
return false;
};
</script>
</head>
<body>
<div id="ControlPanel" style="float: left; width: 50%;">
<div id="ConnectionStatus">
Not Connected
</div>
<br />
<div id="Errors">
No Errors
</div>
<br />
<h3>Test</h3>
Echo: <input type="text" id="test_echo" /><br />
<input type="button" value="Echo" onClick="messageId++; socket.emit('util.echo', {
id: messageId,
text: document.getElementById('test_echo').value,
body: {
description: 'this is in scaffolding.html'
}
});" />
<br /><br />
Group Echo: <input type="text" id="test_echo" /><br />
<input type="button" value="Echo" onClick="messageId++; socket.emit('util.groupEcho', {
id: messageId,
text: document.getElementById('test_echo').value,
body: {
description: 'this is a group message in scaffolding.html'
}
});" />
<br /><br />
Echo as Ack: <input type="text" id="test_echo_ack" /><br />
<input type="button" value="Echo" onClick="messageId++; socket.emit('util.echo', {
id: messageId,
guid: '1111-1111-1111-1111-1111',
text: document.getElementById('test_echo_ack').value,
body: {
description: 'this is in scaffolding.html'
}
}, function(response) {console.log(response)});" />
</div>
<script>
var connectionStatus = document.getElementById('ConnectionStatus');
var data = document.getElementById('Data');
var errors = document.getElementById('Errors');
var token = document.getElementById('api_token');
var formatDate = function(date) {
date = new Date(date);
var mm = date.getMonth() + 1;
var dd = date.getDate();
return [date.getFullYear(), mm < 10 ? '0'+ mm: mm, dd < 10 ? '0'+ dd : dd].join('-');
}
socket = io.connect(socketUri, { transports: ['websocket'] });
socket.on('disconnect', function() {
console.log('disconnected');
});
socket.on('connect', function (response) {
console.log('connected');
socket.emit('auth.register', {
id: 1,
data: {
version: 1
}
});
});
var logs = [];
var Logs = document.getElementById('LogData');
socket.on('log', function (response) {
log(response);
if(logs.length > 10) logs.pop();
logs.unshift(response);
var output = "";
for(var i in logs) output += logs[i] + '<br />';
Logs.innerHTML = output;
});
socket.on('auth.register', function(response) {
if(!response.success) return;
if(response.success) connectionStatus.innerHTML = response.text;
});
socket.on('util.echo', function(response) {
log(response);
});
socket.on('util.groupEcho', function(response) {
log(response);
});
</script>
</body>
</html>