예제 #1
0
파일: app.py 프로젝트: thefinn93/shinysdr
 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')
예제 #2
0
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'))
예제 #3
0
파일: app.py 프로젝트: bitglue/shinysdr
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'))
예제 #4
0
 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')
예제 #5
0
 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)
예제 #6
0
 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)
예제 #7
0
파일: webapp.py 프로젝트: kpreid/shinysdr
 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')
예제 #8
0
 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')
예제 #9
0
 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')
예제 #10
0
 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')
예제 #11
0
 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,
     }))
예제 #12
0
 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)
예제 #13
0
 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)
예제 #14
0
 def render_GET(self, request):
     request.setHeader(b'Content-Type', b'application/json')
     return serialize(self._cell.get()).encode('utf-8')
예제 #15
0
 def test_smoke(self):
     self.assertEqual('"foo"', serialize('foo'))
예제 #16
0
 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)))
예제 #17
0
 def quoted_state_url(self, request, tag):
     return tag(
         serialize(
             self.__wcommon.make_websocket_url(request,
                                               prepath_escaped(request))))
예제 #18
0
파일: app.py 프로젝트: bitglue/shinysdr
 def quoted_state_url(self, request, tag):
     return tag(serialize(self.__wcommon.make_websocket_url(request, prepath_escaped(request) + CAP_OBJECT_PATH_ELEMENT)))
예제 #19
0
파일: app.py 프로젝트: bitglue/shinysdr
 def quoted_audio_url(self, request, tag):
     return tag(serialize(self.__wcommon.make_websocket_url(request, prepath_escaped(request) + 'audio')))
예제 #20
0
 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)))
예제 #21
0
 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 = []
예제 #22
0
 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 = []
예제 #23
0
파일: base.py 프로젝트: yellowsdr/shinysdr
 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)))
예제 #24
0
 def grrender(self, value, request):
     return serialize(value).encode('utf-8')
예제 #25
0
 def grrender(self, value, request):
     return serialize(value).encode('utf-8')
예제 #26
0
 def quoted_audio_url(self, request, tag):
     return tag(
         serialize(
             self.entry_point_wcommon.make_websocket_url(
                 request,
                 prepath_escaped(request) + 'audio')))
예제 #27
0
 def render_GET(self, request):
     request.setHeader(b'Content-Type', b'application/json')
     return serialize(self._cell.get()).encode('utf-8')
예제 #28
0
 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 = []