@@ -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+
95102void 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