parameters: (self, message)
docstring: Receive message from client.
docstring_summary: Receive message from client.
docstring_tokens: Receive message from client .
function: def on_message(self, message):
          """Receive message from client."""
          client = ClientWebSocketHandler.find_client_from_websocket(self)
          if client:
              data = json.loads(message)
              if 'init' in data:
                  # setup client
                  client.streaming_server_port = ClientWebSocketHandler.next_available_port()
                  logging.info('data[init]=%s' % data['init'])
                  client.host = data['init'][0]
                  client.app = data['init'][1]
                  client.world = data['init'][2]
                  client.user1Id = data['init'][3]
                  client.user1Name = data['init'][4]
                  client.user1Authentication = data['init'][5]
                  client.user2Id = data['init'][6]
                  client.user2Name = data['init'][7]
                  client.customData = data['init'][8]
                  client.idle = True
                  # Check that client.host is allowed
                  host = client.host[8:] if client.host.startswith('https://') else client.host[7:]
                  n = host.find(':')
                  if n > 0:
                      host = host[:n]
                  keyFilename = os.path.join(config['keyDir'], host)
                  if os.path.isfile(keyFilename):
                      try:
                          keyFile = open(keyFilename, "r")
                      except IOError:
                          logging.error("Unknown host: " + host + " from " + self.request.remote_ip)
                          client.client_websocket.close()
                          return
                      client.key = keyFile.readline().rstrip(os.linesep)
                      keyFile.close()
                  else:
                      logging.warning("No key for: " + host)
                  logging.info('[%d] Setup client %s %s '
                               '(remote ip: %s, streaming_server_port: %s)'
                               % (id(client),
                                  client.app,
                                  client.world,
                                  self.request.remote_ip,
                                  client.streaming_server_port))
                  self.start_client()
              elif "reset controller" in data:
                  relativeFilename = '/controllers/' + data['reset controller']
                  shutil.copyfile(config['projectsDir'] + '/' + client.app + relativeFilename,
                                  client.project_instance_path + '/' + relativeFilename)
                  self.write_message('reset controller: ' + data['reset controller'])
                  logging.info('[%d] Reset file %s '
                               '(remote ip: %s, streaming_server_port: %s)'
                               % (id(client),
                                  data['reset controller'],
                                  self.request.remote_ip,
                                  client.streaming_server_port))
              elif 'start' in data:  # checkout a github folder and run a simulation in there
                  client.streaming_server_port = ClientWebSocketHandler.next_available_port()
                  client.url = data['start']['url']
                  if 'mode' in data['start']:
                      client.mode = data['start']['mode']
                      if client.mode not in ['x3d', 'mjpeg']:
                          logging.warning("Unsupported client mode: " + client.mode)
                  logging.info('Starting simulation from ' + client.url)
                  self.start_client()
function_tokens: def on_message ( self , message ) : client = ClientWebSocketHandler . find_client_from_websocket ( self ) if client : data = json . loads ( message ) if 'init' in data : # setup client client . streaming_server_port = ClientWebSocketHandler . next_available_port ( ) logging . info ( 'data[init]=%s' % data [ 'init' ] ) client . host = data [ 'init' ] [ 0 ] client . app = data [ 'init' ] [ 1 ] client . world = data [ 'init' ] [ 2 ] client . user1Id = data [ 'init' ] [ 3 ] client . user1Name = data [ 'init' ] [ 4 ] client . user1Authentication = data [ 'init' ] [ 5 ] client . user2Id = data [ 'init' ] [ 6 ] client . user2Name = data [ 'init' ] [ 7 ] client . customData = data [ 'init' ] [ 8 ] client . idle = True # Check that client.host is allowed host = client . host [ 8 : ] if client . host . startswith ( 'https://' ) else client . host [ 7 : ] n = host . find ( ':' ) if n > 0 : host = host [ : n ] keyFilename = os . path . join ( config [ 'keyDir' ] , host ) if os . path . isfile ( keyFilename ) : try : keyFile = open ( keyFilename , "r" ) except IOError : logging . error ( "Unknown host: " + host + " from " + self . request . remote_ip ) client . client_websocket . close ( ) return client . key = keyFile . readline ( ) . rstrip ( os . linesep ) keyFile . close ( ) else : logging . warning ( "No key for: " + host ) logging . info ( '[%d] Setup client %s %s ' '(remote ip: %s, streaming_server_port: %s)' % ( id ( client ) , client . app , client . world , self . request . remote_ip , client . streaming_server_port ) ) self . start_client ( ) elif "reset controller" in data : relativeFilename = '/controllers/' + data [ 'reset controller' ] shutil . copyfile ( config [ 'projectsDir' ] + '/' + client . app + relativeFilename , client . project_instance_path + '/' + relativeFilename ) self . write_message ( 'reset controller: ' + data [ 'reset controller' ] ) logging . info ( '[%d] Reset file %s ' '(remote ip: %s, streaming_server_port: %s)' % ( id ( client ) , data [ 'reset controller' ] , self . request . remote_ip , client . streaming_server_port ) ) elif 'start' in data : # checkout a github folder and run a simulation in there client . streaming_server_port = ClientWebSocketHandler . next_available_port ( ) client . url = data [ 'start' ] [ 'url' ] if 'mode' in data [ 'start' ] : client . mode = data [ 'start' ] [ 'mode' ] if client . mode not in [ 'x3d' , 'mjpeg' ] : logging . warning ( "Unsupported client mode: " + client . mode ) logging . info ( 'Starting simulation from ' + client . url ) self . start_client ( )