MCPcopy Index your code
hub / github.com/rawpython/remi / set_internal_js

Method set_internal_js

remi/gui.py:1360–1622  ·  view source on GitHub ↗
(self, app_identifier, net_interface_ip, pending_messages_queue_length, websocket_timeout_timer_ms)

Source from the content-addressed store, hash-verified

1358 self.add_child("favicon", '<link rel="%s" href="%s" type="%s" />'%(rel, base64_data, mimetype))
1359
1360 def set_internal_js(self, app_identifier, net_interface_ip, pending_messages_queue_length, websocket_timeout_timer_ms):
1361 self.add_child('internal_js',
1362 """
1363 <script>
1364 /*'use strict';*/
1365
1366 var Remi = function() {
1367 this._pendingSendMessages = [];
1368 this._ws = null;
1369 this._comTimeout = null;
1370 this._failedConnections = 0;
1371 this._openSocket();
1372 };
1373
1374 // from http://stackoverflow.com/questions/5515869/string-length-in-bytes-in-javascript
1375 // using UTF8 strings I noticed that the javascript .length of a string returned less
1376 // characters than they actually were
1377 Remi.prototype._byteLength = function(str) {
1378 // returns the byte length of an utf8 string
1379 return str.length;
1380 };
1381
1382 Remi.prototype._paramPacketize = function (ps){
1383 var ret = '';
1384 for (var pkey in ps) {
1385 if( ret.length>0 )ret = ret + '|';
1386 var pstring = pkey+'='+ps[pkey];
1387 var pstring_length = this._byteLength(pstring);
1388 pstring = pstring_length+'|'+pstring;
1389 ret = ret + pstring;
1390 }
1391 return ret;
1392 };
1393
1394 Remi.prototype._openSocket = function(){
1395 var ws_wss = "ws";
1396 try{
1397 ws_wss = document.location.protocol.startsWith('https')?'wss':'ws';
1398 }catch(ex){}
1399
1400 var self = this;
1401 try{
1402 this._ws = new WebSocket(ws_wss + '://%(host)s/');
1403 console.debug('opening websocket');
1404
1405 this._ws.onopen = function(evt){
1406 if(self._ws.readyState == 1){
1407 self._ws.send('connected');
1408
1409 try {
1410 document.getElementById("loading").style.display = 'none';
1411 } catch(err) {
1412 console.log('Error hiding loading overlay ' + err.message);
1413 }
1414
1415 self._failedConnections = 0;
1416
1417 while(self._pendingSendMessages.length>0){

Callers 1

_instanceMethod · 0.80

Calls 1

add_childMethod · 0.80

Tested by

no test coverage detected