total5 0.0.1 → 0.0.2

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/openclient.js ADDED
@@ -0,0 +1,219 @@
1
+ function openclientmessage(msg) {
2
+
3
+ var t = this;
4
+
5
+ if (msg.type === 'init') {
6
+ t.$opensync = msg;
7
+ for (var key in t.$clients) {
8
+ var client = t.$clients[key];
9
+ client.meta = msg;
10
+ client.type = msg.id;
11
+ client.ononline && client.ononline(msg);
12
+ }
13
+ return;
14
+ }
15
+
16
+ if (msg.callbackid) {
17
+ var cb = t.$callbacks[msg.callbackid];
18
+ if (cb) {
19
+ delete t.$callbacks[msg.callbackid];
20
+ cb.timeout && clearTimeout(cb.timeout);
21
+ cb.fn(msg.error, msg.response);
22
+ }
23
+ return;
24
+ }
25
+
26
+ for (var key in t.$clients) {
27
+ var client = t.$clients[key];
28
+ client.onmessage && client.onmessage.call(t, msg);
29
+ }
30
+ }
31
+
32
+ function openclienterror(e) {
33
+
34
+ var t = this;
35
+
36
+ for (var key in t.$callbacks) {
37
+ var cb = t.$callbacks[key];
38
+ if (cb) {
39
+ delete t.$callbacks[key];
40
+ cb.fn(e instanceof Error ? e.message : e);
41
+ }
42
+ }
43
+
44
+ for (var key in t.$clients) {
45
+ var client = t.$clients[key];
46
+ client.onerror && client.onerror.call(t, e instanceof Error ? e.message : e);
47
+ }
48
+ }
49
+
50
+ function openclientopen() {
51
+ var t = this;
52
+ for (var key in t.$clients) {
53
+ var client = t.$clients[key];
54
+ client.connected = true;
55
+ }
56
+ }
57
+
58
+ function openclientclose(code, message) {
59
+ var t = this;
60
+ for (var key in t.$clients) {
61
+ var client = t.$clients[key];
62
+ if (code > 3999)
63
+ client.onerror && client.onerror(code, message);
64
+ client.ononline && client.ononline(null);
65
+ client.connected = false;
66
+ }
67
+ }
68
+
69
+ function openclienttimeout(ws, key) {
70
+ var cb = ws.$callbacks[key];
71
+ if (cb) {
72
+ cb.fn('timeout');
73
+ cb.timeout = null;
74
+ delete ws.$callbacks[key];
75
+ }
76
+ }
77
+
78
+ exports.create = function(url, id) {
79
+
80
+ url = url.replace(/^http/, 'ws');
81
+
82
+ if (id) {
83
+ for (var key in F.openclients) {
84
+ var client = F.openclients[key];
85
+ if (client.$clients[id])
86
+ client.$clients[id].remove();
87
+ }
88
+ } else
89
+ id = GUID(10);
90
+
91
+ var opt = {};
92
+ opt.id = id;
93
+ opt.url = url;
94
+
95
+ opt.send2 = function(msg, callback, filter, timeout) {
96
+
97
+ if (typeof(filter) === 'number') {
98
+ timeout = filter;
99
+ filter = null;
100
+ }
101
+
102
+ var t = this;
103
+ if (!t.ws.closed) {
104
+ if (callback) {
105
+ var key = (t.ws.$callbackindexer++) + '';
106
+ t.ws.$callbacks[key] = { id: opt.id, fn: callback };
107
+ if (timeout)
108
+ t.ws.$callbacks[key].timeout = setTimeout(openclienttimeout, timeout, t.ws, key);
109
+ msg.callbackid = key;
110
+ }
111
+ t.ws.send(msg, filter);
112
+ } else if (callback)
113
+ callback('offline');
114
+ return !t.ws.closed;
115
+ };
116
+
117
+ opt.rpc = function(msg, callback, filter, timeout) {
118
+
119
+ if (callback && typeof(callback) !== 'function') {
120
+ timeout = filter;
121
+ filter = callback;
122
+ callback = null;
123
+ }
124
+
125
+ if (callback)
126
+ return opt.send(msg, callback, filter, timeout);
127
+ else {
128
+ var promise = new Promise((resolve, reject) => opt.send(msg, function(err, res) {
129
+ if (err) {
130
+ err.name = 'OPENCLIENT(' + opt.url + ')';
131
+ reject(err);
132
+ } else
133
+ resolve(res);
134
+ }, filter, timeout));
135
+ return promise;
136
+ }
137
+ };
138
+
139
+ opt.cmd = function(msg, filter, timeout) {
140
+ return opt.send(msg, null, filter, timeout);
141
+ };
142
+
143
+ opt.send = function(msg, callback, filter, timeout, count) {
144
+
145
+ if (!opt.ws || count > 10) {
146
+ callback && callback('offline');
147
+ return;
148
+ }
149
+
150
+ if (opt.ws.closed) {
151
+ if (opt.ws && opt.ws.$clients[opt.id])
152
+ setTimeout(opt.send, 500, msg, callback, filter, timeout, (count || 0) + 1);
153
+ else if (callback)
154
+ callback('offline');
155
+ } else
156
+ opt.send2(msg, callback, filter, timeout);
157
+
158
+ return opt;
159
+ };
160
+
161
+ opt.close = opt.remove = function() {
162
+ var t = this;
163
+ var client = t.ws.$clients[t.id];
164
+ client.destroy && client.destroy();
165
+ delete t.ws.$clients[t.id];
166
+
167
+ for (var key in t.ws.$callbacks) {
168
+ var cb = t.ws.$callbacks[key];
169
+ if (cb.id === t.id) {
170
+ cb.timeout && clearTimeout(cb.timeout);
171
+ cb.fn('offline');
172
+ delete t.ws.$callbacks[key];
173
+ }
174
+ }
175
+
176
+ if (!Object.keys(t.ws.$clients).length) {
177
+ t.ws.close();
178
+ delete F.openclients[t.url];
179
+ }
180
+ };
181
+
182
+ opt.message = function(fn) {
183
+ opt.onmessage = fn;
184
+ return opt;
185
+ };
186
+
187
+ opt.error = function(fn) {
188
+ opt.onerror = fn;
189
+ return opt;
190
+ };
191
+
192
+ opt.online = function(fn) {
193
+ opt.ononline = fn;
194
+ return opt;
195
+ };
196
+
197
+ opt.ws = F.openclients[url];
198
+
199
+ if (!opt.ws) {
200
+ opt.ws = F.websocketclient();
201
+ setImmediate(() => opt.ws.connect(url));
202
+ F.openclients[url] = opt.ws;
203
+ opt.ws.options.reconnectserver = true;
204
+ opt.ws.$clients = {};
205
+ opt.ws.$callbacks = {};
206
+ opt.ws.$callbackindexer = 0;
207
+ opt.ws.on('message', openclientmessage);
208
+ opt.ws.on('error', openclienterror);
209
+ opt.ws.on('open', openclientopen);
210
+ opt.ws.on('close', openclientclose);
211
+ } else if (!opt.ws.closed && opt.ws.$opensync) {
212
+ opt.meta = opt.ws.$opensync;
213
+ opt.type = opt.ws.$opensync.id;
214
+ opt.ononline && opt.ononline(opt.meta);
215
+ }
216
+
217
+ opt.ws.$clients[opt.id] = opt;
218
+ return opt;
219
+ };
package/package.json CHANGED
@@ -1,19 +1,28 @@
1
1
  {
2
2
  "name": "total5",
3
- "version": "0.0.1",
4
- "description": "Total.js version 5.",
3
+ "version": "0.0.2",
4
+ "description": "Total.js framework v5",
5
5
  "main": "index.js",
6
+ "directories": {
7
+ "test": "test"
8
+ },
9
+ "bin": {
10
+ "total5": "./bin/total5",
11
+ "flow5": "./bin/flow5"
12
+ },
6
13
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
14
+ "test": "cd tests && node run.js"
8
15
  },
9
16
  "repository": {
10
17
  "type": "git",
11
18
  "url": "git+https://github.com/totaljs/framework5.git"
12
19
  },
13
20
  "keywords": [
21
+ "total.js",
22
+ "total5",
14
23
  "framework",
15
- "platform",
16
- "mvc"
24
+ "web",
25
+ "platform"
17
26
  ],
18
27
  "author": "Peter Širka",
19
28
  "license": "MIT",
package/pause.html ADDED
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Please wait</title>
5
+ <meta charset="utf-8" />
6
+ <meta name="format-detection" content="telephone=no" />
7
+ <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
8
+ <meta name="robots" content="all,follow" />
9
+ <style type="text/css">
10
+ /*auto*/
11
+ html,body { font: normal normal 14px Arial; background-color: white; height: 100%; margin: 0; padding: 0; font-smoothing: antialiased; }
12
+ .table { display: table; width: 100%; height: 100%}
13
+ .cell { display:table-cell;vertical-align:middle;text-align:center}
14
+ table { max-width: 300px; margin: 20px auto; width: 100%; border:1px solid #E0E0E0; border-collapse: collapse; font-size: 12px; }
15
+ table td { border: 1px solid #E0E0E0; padding: 6px 8px; text-align: center; }
16
+ table td:first-child { text-align: left; width: 85%; }
17
+ .anim { animation: anim 2s infinite; }
18
+ .text { color: #A0A0A0; font-size: 10px; margin-bottom: 3px; }
19
+ #time { font-size: 60px; font-weight: bold; margin-bottom: 10px; background-color: #000; color: #FFF; padding: 8px 15px; min-width: 70px; text-align: center; border-radius: 10px; position: relative; display: inline-block; border-bottom: 5px solid #D0D0D0; }
20
+
21
+ @keyframes anim {
22
+ 0% { transform:scale(1); }
23
+ 50%{ transform:scale(1.5) rotate(180deg); color:gray }
24
+ 100%{ transform:scale(1); }
25
+ }
26
+ </style>
27
+ </head>
28
+ <body>
29
+
30
+ <div class="table">
31
+ <div class="cell">
32
+ <div id="time">10</div>
33
+ <div class="text">Please wait</div>
34
+ <div>
35
+ <b>Application is starting &hellip;</b>
36
+ </div>
37
+ <table>
38
+ @{foreach m in model}
39
+ <tr>
40
+ <td>@{m}</td>
41
+ <td class="anim">&#10711;</td>
42
+ </tr>
43
+ @{end}
44
+ </table>
45
+ </div>
46
+ </div>
47
+
48
+ <script>
49
+ var counter = 10;
50
+
51
+ setInterval(function() {
52
+
53
+ if (counter < 0)
54
+ return;
55
+
56
+ if (counter === 0)
57
+ window.location.reload();
58
+ else
59
+ time.innerHTML = counter + '';
60
+
61
+ counter--;
62
+
63
+ }, 1000);
64
+ </script>
65
+
66
+ </body>
67
+ </html>