Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def init_socket(self):
""" Make the connection to Python.
"""
# Check WebSocket support
WebSocket = window.WebSocket
if (WebSocket is undefined):
window.document.body.textContent = 'Browser does not support WebSockets'
raise "FAIL: need websocket"
# Construct ws url
if not self.ws_url:
proto = 'ws'
if window.location.protocol == 'https:':
proto = 'wss'
address = window.location.hostname
if window.location.port:
address += ':' + window.location.port
self.ws_url = '%s://%s/flexx/ws/%s' % (proto, address, self.app_name)
# Resolve public hostname
self.ws_url = self.ws_url.replace('0.0.0.0', window.location.hostname)
# Open web socket in binary mode
self._ws = ws = WebSocket(self.ws_url)
ws.binaryType = "arraybuffer"
self.status = 2
def on_ws_open(evt):
window.console.info('Socket opened with session id ' + self.id)
self.send_command('HI_FLEXX', self.id)
def on_ws_message(evt):
msg = evt.data # bsdf-encoded command
if not msg:
pass # ? drop glitchy message :/
# not work because these won't be loaded on time.
el = window.document.createElement("script")
el.id = name
el.innerHTML = code
window.flexx.asset_node.appendChild(el)
elif kind == 'CSS':
el = window.document.createElement("style")
el.type = "text/css"
el.id = name
el.innerHTML = code
window.flexx.asset_node.appendChild(el)
else:
window.console.error('Dont know how to DEFINE ' +
name + ' with "' + kind + '".')
elif cmd == 'OPEN':
window.win1 = window.open(command[1], 'new', 'chrome')
else:
window.console.error('Invalid command: "' + cmd + '"')
return command
def init_socket(self):
""" Make the connection to Python.
"""
# Check WebSocket support
WebSocket = window.WebSocket
if (WebSocket is undefined):
window.document.body.textContent = 'Browser does not support WebSockets'
raise "FAIL: need websocket"
# Construct ws url
if not self.ws_url:
proto = 'ws'
if window.location.protocol == 'https:':
proto = 'wss'
address = window.location.hostname
if window.location.port:
address += ':' + window.location.port
self.ws_url = '%s://%s/flexx/ws/%s' % (proto, address, self.app_name)
# Resolve public hostname
self.ws_url = self.ws_url.replace('0.0.0.0', window.location.hostname)
# Open web socket in binary mode
def _remove_querystring(self):
# remove querystring ?session=x
try:
window.history.replaceState(window.history.state, '',
window.location.pathname)
except Exception:
pass # e.g. firefox-app/nw
self._init_time = time()
self._pending_commands = [] # to pend raw commands during init
self._asset_count = 0
self._ws = None
self.last_msg = None
# self.classes = {}
self.instances = {}
self.instances_to_check_size = {}
if not window.flexx.is_exported:
self.init_socket()
# Initiate service to track resize
# Note that only toplevel widgets are tracked, and only once per sec
window.addEventListener('resize', self._check_size_of_objects, False)
window.setInterval(self._check_size_of_objects, 1000)