def render_GET(self, request): request.setHeader(b'Content-Type', b'application/manifest+json') manifest = { 'lang': 'en-US', 'name': self.__title, 'short_name': self.__title if len(self.__title) <= 12 else 'ShinySDR', 'scope': '/', 'icons': [ { 'src': '/client/icon/icon-32.png', 'type': 'image/png', 'sizes': '32x32', }, { 'src': '/client/icon/icon.svg', 'type': 'image/svg', 'sizes': 'any', }, ], 'display': 'minimal-ui', 'orientation': 'any', 'theme_color': '#B9B9B9', # same as gray.css --shinysdr-theme-column-bgcolor 'background_color': '#2F2F2F', # note this is our loading screen color } return serialize(manifest).encode('utf-8')
def _put_plugin_resources(client_resource): # Plugin resources and plugin info load_list_css = [] load_list_js = [] mode_table = {} plugin_resources = Resource() client_resource.putChild('plugins', plugin_resources) for resource_def in getPlugins(_IClientResourceDef, shinysdr.plugins): # Add the plugin's resource to static serving plugin_resources.putChild(resource_def.key, resource_def.resource) plugin_resource_url = '/client/plugins/' + urllib.parse.quote( resource_def.key, safe='') + '/' # Tell the client to load the plugins # TODO constrain path values to be relative (not on a different origin, to not leak urls) if resource_def.load_css_path is not None: load_list_css.append(plugin_resource_url + resource_def.load_cs_path) if resource_def.load_js_path is not None: # TODO constrain value to be in the directory load_list_js.append(plugin_resource_url + resource_def.load_js_path) for mode_def in get_modes(): mode_table[mode_def.mode] = { u'info_enum_row': mode_def.info.to_json(), u'can_transmit': mode_def.mod_class is not None } # Client gets info about plugins through this resource client_resource.putChild( 'plugin-index.json', static.Data( serialize({ u'css': load_list_css, u'js': load_list_js, u'modes': mode_table, }).encode('utf-8'), b'application/json'))
def _put_plugin_resources(client_resource): # Plugin resources and plugin info load_list_css = [] load_list_js = [] mode_table = {} plugin_resources = Resource() client_resource.putChild('plugins', plugin_resources) for resource_def in getPlugins(IClientResourceDef, shinysdr.plugins): # Add the plugin's resource to static serving plugin_resources.putChild(resource_def.key, resource_def.resource) plugin_resource_url = '/client/plugins/' + urllib.quote(resource_def.key, safe='') + '/' # Tell the client to load the plugins # TODO constrain path values to be relative (not on a different origin, to not leak urls) if resource_def.load_css_path is not None: load_list_css.append(plugin_resource_url + resource_def.load_cs_path) if resource_def.load_js_path is not None: # TODO constrain value to be in the directory load_list_js.append(plugin_resource_url + resource_def.load_js_path) for mode_def in get_modes(): mode_table[mode_def.mode] = { u'info_enum_row': mode_def.info.to_json(), u'can_transmit': mode_def.mod_class is not None } # Client gets info about plugins through this resource client_resource.putChild('plugin-index.json', static.Data(serialize({ u'css': load_list_css, u'js': load_list_js, u'modes': mode_table, }).encode('utf-8'), 'application/json'))
def render_GET(self, request): accept = request.getHeader('Accept') if accept is not None and b'application/json' in accept: # TODO: Implement or obtain correct Accept interpretation request.setHeader(b'Content-Type', b'application/json') return serialize(self.__describe_block()).encode('utf-8') else: request.setHeader(b'Content-Type', b'text/html;charset=utf-8') return template.renderElement(request, self.__element)
def render_GET(self, request): accept = request.getHeader('Accept') if accept is not None and 'application/json' in accept: # TODO: Implement or obtain correct Accept interpretation request.setHeader('Content-Type', 'application/json') return serialize(self.__describe_block()).encode('utf-8') else: request.setHeader('Content-Type', 'text/html;charset=utf-8') return renderElement(request, self.__element)
def render_GET(self, request): request.setHeader(b'Content-Type', b'application/json') configuration = { 'plugins': self.__plugin_index, # TODO: oughta be a shorter path to this -- normally websocket url is constructed from a http url gotten from the request so we don't have this exact path 'shared_test_objects_url': self.__wcommon.make_websocket_url(request, _make_cap_url(SHARED_TEST_OBJECTS_CAP) + CAP_OBJECT_PATH_ELEMENT), } return serialize(configuration).encode('utf-8')
def render_GET(self, request): request.setHeader(b'Content-Type', b'application/json') configuration = { 'plugins': self.__plugin_index, # TODO: oughta be a shorter path to this -- normally websocket url is constructed from a http url gotten from the request so we don't have this exact path 'shared_test_objects_url': self.__wcommon.make_websocket_url( request, _make_cap_url(SHARED_TEST_OBJECTS_CAP) + CAP_OBJECT_PATH_ELEMENT), } return serialize(configuration).encode('utf-8')
def render_POST(self, request): """currently only meaningful to create children of CollectionResources""" block = self._block if not IWritableCollection.providedBy(block): raise Exception('Block is not a writable collection') assert request.getHeader('Content-Type') == 'application/json' reqjson = json.load(request.content) key = block.create_child(reqjson) # note may fail url = request.prePathURL() + '/receivers/' + urllib.quote(key, safe='') request.setResponseCode(201) # Created request.setHeader('Location', url) # TODO consider a more useful response return serialize(url).encode('utf-8')
def __init__(self, reactor, send, audio_source, audio_rate): self._send = send self.__audio_source = audio_source self.__callback = self.__deliver # identical object just to avoid any confusion self.__audio_source.add_audio_callback(self.__callback, audio_rate) # We don't actually benefit specifically from using a SignalType in this context but it avoids reinventing vocabulary. signal_type = SignalType( kind='STEREO' if self.__audio_source.get_audio_callback_channels() == 2 else 'MONO', sample_rate=audio_rate) send(serialize({ # Not used to discriminate, but it seems worth applying the convention in general. u'type': u'audio_stream_metadata', u'signal_type': signal_type, }))
def __init__(self, reactor, send, block, audio_rate): self._send = send self._queue = gr.msg_queue(limit=100) self.__running = [True] self._block = block self._block.add_audio_queue(self._queue, audio_rate) # We don't actually benefit specifically from using a SignalType in this context but it avoids reinventing vocabulary. signal_type = SignalType( kind='STEREO' if self._block.get_audio_queue_channels() == 2 else 'MONO', sample_rate=audio_rate) send(serialize({ # Not used to discriminate, but it seems worth applying the convention in general. u'type': u'audio_stream_metadata', u'signal_type': signal_type, })) reactor.callInThread(_AudioStream_read_loop, reactor, self._queue, self.__deliver, self.__running)
def render_GET(self, request): request.setHeader(b'Content-Type', b'application/json') return serialize(self._cell.get()).encode('utf-8')
def test_smoke(self): self.assertEqual('"foo"', serialize('foo'))
def quoted_audio_url(self, request, tag): return tag( serialize( self.entry_point_wcommon.make_websocket_url( request, prepath_escaped(request) + AUDIO_STREAM_PATH_ELEMENT)))
def quoted_state_url(self, request, tag): return tag( serialize( self.__wcommon.make_websocket_url(request, prepath_escaped(request))))
def quoted_state_url(self, request, tag): return tag(serialize(self.__wcommon.make_websocket_url(request, prepath_escaped(request) + CAP_OBJECT_PATH_ELEMENT)))
def quoted_audio_url(self, request, tag): return tag(serialize(self.__wcommon.make_websocket_url(request, prepath_escaped(request) + 'audio')))
def quoted_audio_url(self, request, tag): return tag(serialize(self.entry_point_wcommon.make_websocket_url(request, prepath_escaped(request) + AUDIO_STREAM_PATH_ELEMENT)))
def _flush(self): # exposed for testing self.__batch_delay = None if len(self._send_batch) > 0: # unicode() because JSONEncoder does not reliably return a unicode rather than str object self._send(unicode(serialize(self._send_batch))) self._send_batch = []
def _flush(self): # exposed for testing self.__batch_delay = None if len(self._send_batch) > 0: self._send(serialize(self._send_batch)) self._send_batch = []
def quoted_state_url(self, request, tag): return tag(serialize(self.entry_point_wcommon.make_websocket_url(request, prepath_escaped(request) + CAP_OBJECT_PATH_ELEMENT)))
def grrender(self, value, request): return serialize(value).encode('utf-8')
def quoted_audio_url(self, request, tag): return tag( serialize( self.entry_point_wcommon.make_websocket_url( request, prepath_escaped(request) + 'audio')))