Skip to content

Commit 4cb64ba

Browse files
committed
Replaced fhq to sClassName for export webjs
1 parent aa7ab51 commit 4cb64ba

File tree

8 files changed

+74
-63
lines changed

8 files changed

+74
-63
lines changed

example-of-exported/py3/API.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Automatically generated by wsjcpp-jsonrpc20.
44
* Version: v0.0.4
5-
* Date: Mon, 05 Oct 2020 01:15:21 GMT
5+
* Date: Tue, 06 Oct 2020 02:19:51 GMT
66

77
Example connect/disconnect:
88
```

example-of-exported/py3/libwsjcppjson20client/SomeClient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33
### This file was automatically generated by wsjcpp-jsonrpc20
44
### Version: v0.0.4
5-
### Date: Mon, 05 Oct 2020 01:15:21 GMT
5+
### Date: Tue, 06 Oct 2020 02:19:51 GMT
66

77
import asyncio
88
import websocket

example-of-exported/webjs/API.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22

33
Automatically generated by wsjcpp-jsonrpc20.
44
* Version: v0.0.4
5-
* Date: 05 Oct 2020
5+
* Date: 06 Oct 2020
66

7-
Include script ```dist/libfhqcli-web-js.js```
7+
Include script ```dist/libwsjcppjson20client.js```
88
Example connect:
99
```
10-
fhq.bind('server', function(data) { console.log('server', data)})
11-
fhq.bind('notify', function(data) { console.log('notify', data)})
12-
fhq.bind('chat', function(data) { console.log('chat', data)})
13-
fhq.bind('connected', function(data) { console.log('connected', data)})
14-
fhq.bind('reconnecting', function(data) { console.log('reconnecting', data)})
15-
fhq.bind('disconnected', function(data) { console.log('disconnected', data)})
16-
fhq.bind('broken', function(data) { console.log('broken', data)})
17-
fhq.bind('userdata', function(data) { console.log('userdata', data)})
18-
fhq.bind('connected', function(data) { console.log('connected', data)})
10+
var client = new SomeClient();
11+
client.bind('server', function(data) { console.log('server', data)})
12+
client.bind('notify', function(data) { console.log('notify', data)})
13+
client.bind('chat', function(data) { console.log('chat', data)})
14+
client.bind('connected', function(data) { console.log('connected', data)})
15+
client.bind('reconnecting', function(data) { console.log('reconnecting', data)})
16+
client.bind('disconnected', function(data) { console.log('disconnected', data)})
17+
client.bind('broken', function(data) { console.log('broken', data)})
18+
client.bind('userdata', function(data) { console.log('userdata', data)})
19+
client.bind('connected', function(data) { console.log('connected', data)})
1920
// connect
20-
fhq.init({'baseUrl': 'ws://localhost:1234/'})
21+
client.init({'baseUrl': 'ws://localhost:1234/'})
2122
// disconnect
22-
fhq.deinit()
23+
client.deinit()
2324
```
2425

2526
<details>
@@ -42,7 +43,7 @@ Access: unauthorized - **yes**, user - **no**, tester - **no**, admin - **no*
4243
#### example call method
4344

4445
```
45-
fhq.auth_login({
46+
client.auth_login({
4647
"login": "",
4748
"password": "",
4849
"client_app_name": "",
@@ -72,7 +73,7 @@ Access: unauthorized - **no**, user - **yes**, tester - **yes**, admin - **ye
7273
#### example call method
7374

7475
```
75-
fhq.auth_logoff({
76+
client.auth_logoff({
7677
7778
}).done(function(r) {
7879
console.log('Success: ', r);
@@ -102,7 +103,7 @@ Access: unauthorized - **yes**, user - **no**, tester - **no**, admin - **no*
102103
#### example call method
103104

104105
```
105-
fhq.auth_token({
106+
client.auth_token({
106107
"token": "",
107108
"client_app_name": "",
108109
"client_app_version": ""
@@ -138,7 +139,7 @@ Access: unauthorized - **no**, user - **yes**, tester - **yes**, admin - **ye
138139
#### example call method
139140

140141
```
141-
fhq.game_create({
142+
client.game_create({
142143
"uuid": "",
143144
"name": "",
144145
"cost": 0,
@@ -171,7 +172,7 @@ Access: unauthorized - **yes**, user - **yes**, tester - **yes**, admin - **y
171172
#### example call method
172173

173174
```
174-
fhq.server_api({
175+
client.server_api({
175176
176177
}).done(function(r) {
177178
console.log('Success: ', r);

example-of-exported/webjs/dist/libwsjcppjson20client.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// This file was automatically generated by wsjcpp-jsonrpc20 (v0.0.4), date: 05 Oct 2020
1+
// This file was automatically generated by wsjcpp-jsonrpc20 (v0.0.4), date: 06 Oct 2020
22
window.SomeClient = window.SomeClient || (function() {
33
var self = {};
44
self.appName = 'wsjcpp-jsonrpc20';
55
self.appVersion = 'v0.0.4';
6-
self.appBuildDate = '05 Oct 2020';
6+
self.appBuildDate = '06 Oct 2020';
77
var _lastm = 0;
88
var _listeners = {};
99
var _connectionState = '?';
@@ -76,14 +76,14 @@ window.SomeClient = window.SomeClient || (function() {
7676
};
7777
self.setToken = function(token) {
7878
var date = new Date( new Date().getTime() + (7 * 24 * 60 * 60 * 1000) ); // cookie on week
79-
document.cookie = 'fhqtoken=' + encodeURIComponent(token) + '; path=/; expires='+date.toUTCString();
79+
document.cookie = 'SomeClienttoken=' + encodeURIComponent(token) + '; path=/; expires='+date.toUTCString();
8080
}
8181
self.removeToken = function() {
82-
_tokenValue = ''; document.cookie = 'fhqtoken=; path=/;';
82+
_tokenValue = ''; document.cookie = 'SomeClienttoken=; path=/;';
8383
}
8484
self.getToken = function() {
8585
var matches = document.cookie.match(new RegExp(
86-
'(?:^|; )' + 'fhqtoken'.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + '=([^;]*)'
86+
'(?:^|; )' + 'SomeClienttoken'.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + '=([^;]*)'
8787
));
8888
return matches ? decodeURIComponent(matches[1]) : '';
8989
}
@@ -216,7 +216,7 @@ window.SomeClient = window.SomeClient || (function() {
216216
if (params['password'] == undefined) {
217217
console.error('Parameter "password" expected (lib)');
218218
}
219-
return self.send(params);
219+
return self.send(params);
220220
}
221221

222222
self.auth_logoff = function(params) {
@@ -227,7 +227,7 @@ window.SomeClient = window.SomeClient || (function() {
227227
// Activated From Version: v0.0.2
228228
params = params || {};
229229
params.cmd = 'auth_logoff';
230-
return self.send(params);
230+
return self.send(params);
231231
}
232232

233233
self.auth_token = function(params) {
@@ -245,7 +245,7 @@ window.SomeClient = window.SomeClient || (function() {
245245
if (params['token'] == undefined) {
246246
console.error('Parameter "token" expected (lib)');
247247
}
248-
return self.send(params);
248+
return self.send(params);
249249
}
250250

251251
self.game_create = function(params) {
@@ -273,7 +273,7 @@ window.SomeClient = window.SomeClient || (function() {
273273
if (params['public'] == undefined) {
274274
console.error('Parameter "public" expected (lib)');
275275
}
276-
return self.send(params);
276+
return self.send(params);
277277
}
278278

279279
self.server_api = function(params) {
@@ -283,7 +283,7 @@ window.SomeClient = window.SomeClient || (function() {
283283
// Access admin: yes
284284
params = params || {};
285285
params.cmd = 'server_api';
286-
return self.send(params);
286+
return self.send(params);
287287
}
288288

289289
return self;

example-of-exported/webjs/sample.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,24 @@
77
var log = document.getElementById('log');
88
log.innerHTML += '[' + new Date() + '] ' + n + '\r\n';
99
};
10+
var client = new SomeClient();
1011
document.addEventListener('DOMContentLoaded', function() {
11-
fhq.bind('notify', function(data) {
12+
client.bind('notify', function(data) {
1213
log('notify: ' + JSON.stringify(data))
1314
});
14-
fhq.bind('connected', function(data) {
15+
client.bind('connected', function(data) {
1516
log('connected: ' + JSON.stringify(data))
1617
connecting_form.style.display = 'none';
1718
login_form.style.display = '';
1819
logout_form.style.display = 'none';
1920
});
20-
fhq.bind('disconnected', function(data) {
21+
client.bind('disconnected', function(data) {
2122
log('disconnected: ' + JSON.stringify(data))
2223
connecting_form.style.display = '';
2324
login_form.style.display = 'none';
2425
logout_form.style.display = 'none';
2526
});
26-
fhq.bind('userdata', function(data) {
27+
client.bind('userdata', function(data) {
2728
log('userdata: ' + JSON.stringify(data))
2829
login_form.style.display = 'none';
2930
logout_form.style.display = '';
@@ -50,17 +51,17 @@ <h1>Connected</h1>
5051
<script>
5152
server_url.value = 'ws://' + window.location.hostname + ':1234/api-ws/'
5253
btn_login.onclick = function() {
53-
fhq.login({email: login.value, password: password.value}).done(function(r) {
54+
client.login({email: login.value, password: password.value}).done(function(r) {
5455
log('Login success, token = ' + r.token);
5556
}).fail(function(e) {
5657
log('Login failed, error = ' + e.error);
5758
})
5859
}
5960
btn_logout.onclick = function() {
60-
fhq.deinit();
61+
client.deinit();
6162
}
6263
btn_connect.onclick = function() {
63-
fhq.init({'baseUrl': server_url.value});
64+
client.init({'baseUrl': server_url.value});
6465
}
6566
</script>
6667
<pre id='log'></pre>

src/app/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ int main(int argc, const char* argv[]) {
5757
exportCliWebJs.setRepository("git", "https://github.com/wsjcpp/wsjcpp-jsonrpc20.git");
5858
exportCliWebJs.setKeywords({std::string(WSJCPP_APP_NAME), "wsjcpp", "jsonrpc20", "example-client-webjs"});
5959
exportCliWebJs.setLicense("MIT", "https://raw.githubusercontent.com/wsjcpp/wsjcpp-jsonrpc20/master/LICENSE");
60-
// exportCliWebJs.setUrl("https://github.com/wsjcpp/wsjcpp-jsonrpc20");
61-
// exportCliWebJs.setDownloadUrl("https://github.com/wsjcpp/wsjcpp-jsonrpc20/archive/" + std::string(WSJCPP_APP_NAME) + ".tar.gz");
60+
exportCliWebJs.setDefaultConnectionString("ws://localhost:1234/");
6261

6362
// exportCliWebJs.addLoginMethod("auth_login", "token");
6463
// exportCliWebJs.addLoginMethod("auth_token", "token");

src/wsjcpp_jsonrpc20_export_cli_webjs.cpp

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ WsjcppJsonRpc20ExportCliWebJs::WsjcppJsonRpc20ExportCliWebJs(
2828
m_sAppName = "unknown";
2929
m_sAppVersion = "unknown";
3030
m_sClassName = "Unknown";
31-
31+
m_sDefaultConnectionString = "ws://localhost:1234/";
32+
3233
// TODO must be WsjcppJsonRpc20::eventsList() or something like
3334
m_vEvents.push_back("server");
3435
m_vEvents.push_back("notify");
@@ -92,6 +93,12 @@ void WsjcppJsonRpc20ExportCliWebJs::setLicense(const std::string &sLicenseType,
9293

9394
// ---------------------------------------------------------------------
9495

96+
void WsjcppJsonRpc20ExportCliWebJs::setDefaultConnectionString(const std::string &sDefaultConnectionString) {
97+
m_sDefaultConnectionString = sDefaultConnectionString;
98+
}
99+
100+
// ---------------------------------------------------------------------
101+
95102
void WsjcppJsonRpc20ExportCliWebJs::setAppVersion(const std::string &sAppVersion) {
96103
m_sAppVersion = sAppVersion;
97104
}
@@ -192,25 +199,26 @@ void WsjcppJsonRpc20ExportCliWebJs::exportAPImd() {
192199
std::stringstream buffer;
193200
buffer << std::put_time(std::gmtime(&t), "%d %b %Y");
194201

195-
// TODO redesign
196202
apimd <<
197203
"# " + m_sPackageName + "\n\n"
198204
" Automatically generated by " << m_sAppName << ". \n"
199205
" * Version: " << m_sAppVersion << "\n"
200206
" * Date: " << buffer.str() << "\n\n"
201-
" Include script ```dist/libfhqcli-web-js.js```\n"
207+
" Include script ```dist/" + m_sPackageName + ".js```\n"
202208
" Example connect:\n"
203-
"```\n";
209+
"```\n"
210+
"var client = new " + m_sClassName + "();\n"
211+
;
204212
for (int i = 0; i < m_vEvents.size(); i++) {
205213
apimd <<
206-
"fhq.bind('" + m_vEvents[i] + "', function(data) { console.log('" + m_vEvents[i] + "', data)})\n";
214+
"client.bind('" + m_vEvents[i] + "', function(data) { console.log('" + m_vEvents[i] + "', data)})\n";
207215
}
208216
apimd <<
209-
"fhq.bind('connected', function(data) { console.log('connected', data)})\n"
217+
"client.bind('connected', function(data) { console.log('connected', data)})\n"
210218
"// connect\n"
211-
"fhq.init({'baseUrl': 'ws://localhost:1234/'})\n"
219+
"client.init({'baseUrl': '" + m_sDefaultConnectionString + "'})\n"
212220
"// disconnect\n"
213-
"fhq.deinit()\n"
221+
"client.deinit()\n"
214222
"```\n"
215223
"\n";
216224

@@ -262,7 +270,7 @@ void WsjcppJsonRpc20ExportCliWebJs::exportAPImd() {
262270
"\n\n"
263271
" #### example call method \n\n"
264272
"```\n"
265-
"fhq." + sCmd + "({\n" + jsTemplate + "\n}).done(function(r) {\n"
273+
"client." + sCmd + "({\n" + jsTemplate + "\n}).done(function(r) {\n"
266274
" console.log('Success: ', r);\n"
267275
"}).fail(function(err) {\n"
268276
" console.error('Error:', err);\n"
@@ -294,23 +302,24 @@ void WsjcppJsonRpc20ExportCliWebJs::exportSampleHtmlFile() {
294302
" var log = document.getElementById('log');\r\n"
295303
" log.innerHTML += '[' + new Date() + '] ' + n + '\\r\\n';\r\n"
296304
" };\r\n"
305+
" var client = new " + m_sClassName + "();\r\n"
297306
" document.addEventListener('DOMContentLoaded', function() {\r\n"
298-
" fhq.bind('notify', function(data) {\r\n"
307+
" client.bind('notify', function(data) {\r\n"
299308
" log('notify: ' + JSON.stringify(data))\r\n"
300309
" });\r\n"
301-
" fhq.bind('connected', function(data) {\r\n"
310+
" client.bind('connected', function(data) {\r\n"
302311
" log('connected: ' + JSON.stringify(data))\r\n"
303312
" connecting_form.style.display = 'none';\r\n"
304313
" login_form.style.display = '';\r\n"
305314
" logout_form.style.display = 'none';\r\n"
306315
" });\r\n"
307-
" fhq.bind('disconnected', function(data) {\r\n"
316+
" client.bind('disconnected', function(data) {\r\n"
308317
" log('disconnected: ' + JSON.stringify(data))\r\n"
309318
" connecting_form.style.display = '';\r\n"
310319
" login_form.style.display = 'none';\r\n"
311320
" logout_form.style.display = 'none';\r\n"
312321
" });\r\n"
313-
" fhq.bind('userdata', function(data) {\r\n"
322+
" client.bind('userdata', function(data) {\r\n"
314323
" log('userdata: ' + JSON.stringify(data))\r\n"
315324
" login_form.style.display = 'none';\r\n"
316325
" logout_form.style.display = '';\r\n"
@@ -337,17 +346,17 @@ void WsjcppJsonRpc20ExportCliWebJs::exportSampleHtmlFile() {
337346
"<script>\r\n"
338347
" server_url.value = 'ws://' + window.location.hostname + ':1234/api-ws/'\r\n"
339348
" btn_login.onclick = function() {\r\n"
340-
" fhq.login({email: login.value, password: password.value}).done(function(r) { \r\n"
349+
" client.login({email: login.value, password: password.value}).done(function(r) { \r\n"
341350
" log('Login success, token = ' + r.token);\r\n"
342351
" }).fail(function(e) {\r\n"
343352
" log('Login failed, error = ' + e.error);\r\n"
344353
" })\r\n"
345354
" }\r\n"
346355
" btn_logout.onclick = function() {\r\n"
347-
" fhq.deinit();\r\n"
356+
" client.deinit();\r\n"
348357
" }\r\n"
349358
" btn_connect.onclick = function() {\r\n"
350-
" fhq.init({'baseUrl': server_url.value});\r\n"
359+
" client.init({'baseUrl': server_url.value});\r\n"
351360
" }\r\n"
352361
"</script>\r\n"
353362
"<pre id='log'></pre>\r\n"
@@ -451,15 +460,15 @@ bool WsjcppJsonRpc20ExportCliWebJs::exportLibCliWebJSFile() {
451460
" };\r\n"
452461
" self.setToken = function(token) {\r\n"
453462
" var date = new Date( new Date().getTime() + (7 * 24 * 60 * 60 * 1000) ); // cookie on week\r\n"
454-
" document.cookie = 'fhqtoken=' + encodeURIComponent(token) + '; path=/; expires='+date.toUTCString();\r\n"
463+
" document.cookie = '" + m_sClassName + "token=' + encodeURIComponent(token) + '; path=/; expires='+date.toUTCString();\r\n"
455464
" }\r\n"
456465
" self.removeToken = function() {\r\n"
457466
" _tokenValue = '';"
458-
" document.cookie = 'fhqtoken=; path=/;';\r\n"
467+
" document.cookie = '" + m_sClassName + "token=; path=/;';\r\n"
459468
" }\r\n"
460469
" self.getToken = function() {\r\n"
461470
" var matches = document.cookie.match(new RegExp(\r\n"
462-
" '(?:^|; )' + 'fhqtoken'.replace(/([\\.$?*|{}\\(\\)\\[\\]\\\\\\/\\+^])/g, '\\\\$1') + '=([^;]*)'\r\n"
471+
" '(?:^|; )' + '" + m_sClassName + "token'.replace(/([\\.$?*|{}\\(\\)\\[\\]\\\\\\/\\+^])/g, '\\\\$1') + '=([^;]*)'\r\n"
463472
" ));\r\n"
464473
" return matches ? decodeURIComponent(matches[1]) : '';\r\n"
465474
" }\r\n"
@@ -659,7 +668,7 @@ bool WsjcppJsonRpc20ExportCliWebJs::exportLibCliWebJSFile() {
659668
" }\r\n";
660669
} else {
661670
libwjscppcli_web_js_file
662-
<< " return self.send(params);\r\n";
671+
<< " return self.send(params);\r\n";
663672
}
664673

665674
libwjscppcli_web_js_file
@@ -880,15 +889,15 @@ void WsjcppJsonRpc20ExportCliWebJs::exportLibCliWebServiceTSFile() {
880889
" };\r\n"
881890
" self.setToken = function(token) {\r\n"
882891
" var date = new Date( new Date().getTime() + (7 * 24 * 60 * 60 * 1000) ); // cookie on week\r\n"
883-
" document.cookie = 'fhqtoken=' + encodeURIComponent(token) + '; path=/; expires='+date.toUTCString();\r\n"
892+
" document.cookie = '" + m_sClassName + "token=' + encodeURIComponent(token) + '; path=/; expires='+date.toUTCString();\r\n"
884893
" }\r\n"
885894
" self.removeToken = function() {\r\n"
886895
" _tokenValue = '';"
887-
" document.cookie = 'fhqtoken=; path=/;';\r\n"
896+
" document.cookie = '" + m_sClassName + "token=; path=/;';\r\n"
888897
" }\r\n"
889898
" self.getToken = function() {\r\n"
890899
" var matches = document.cookie.match(new RegExp(\r\n"
891-
" '(?:^|; )' + 'fhqtoken'.replace(/([\\.$?*|{}\\(\\)\\[\\]\\\\\\/\\+^])/g, '\\\\$1') + '=([^;]*)'\r\n"
900+
" '(?:^|; )' + '" + m_sClassName + "token'.replace(/([\\.$?*|{}\\(\\)\\[\\]\\\\\\/\\+^])/g, '\\\\$1') + '=([^;]*)'\r\n"
892901
" ));\r\n"
893902
" return matches ? decodeURIComponent(matches[1]) : '';\r\n"
894903
" }\r\n"

0 commit comments

Comments
 (0)