coherence.web (package)¶
coherence.web.ui (module)¶
WebUI¶
The WebUI
is used to enable an html interface where the user can
browse the devices content via web browser. By default, the WebUI interface
is disabled and could be enabled from config file or by config dictionary when
initializing Coherence
Changed in version 0.8.2.
Note
Be aware that the browser should support Web Sockets and js enabled. All modern browsers should have this features integrated (tested with firefox and google chrome).
Warning
Don’t create your web server into port 9000. This is reserved for the js WebSocket.
WebUi Example¶
A simple server with web-ui enabled:
from coherence.base import Coherence
from coherence.upnp.core.uuid import UUID
from twisted.internet import reactor
new_uuid = UUID()
coherence = Coherence(
{'web-ui': 'yes',
'serverport': '9001',
'logmode': 'info',
'controlpoint': 'yes',
'plugin': {'backend': 'FSStore',
'name': 'WEB UI FSStore',
'content': 'path-to-a-directory-with-media-content',
'uuid': new_uuid
}
}
)
reactor.run()
-
class
WSBroadcastServerProtocol
[source]¶ Bases:
autobahn.twisted.websocket.WebSocketServerProtocol
WSBroadcastServerProtocol deals with the async WebSocket client connection.
New in version 0.8.2.
Changed in version 0.9.0: Migrated from louie/dispatcher to EventDispatcher
Note
We can attach a callback into the variable message_callback, this callback will be triggered whenever onMessage is called.
-
factory
= None¶
-
message_callback
= None¶
-
-
class
WSBroadcastServerFactory
(client_tracker)[source]¶ Bases:
autobahn.twisted.websocket.WebSocketServerFactory
WSBroadcastServerFactory is the central WebSocket server side component shared between connections.
New in version 0.8.2.
-
class
WSClientTracker
[source]¶ Bases:
object
Helper to keep track of connections, accessed by the sync and async methods.
New in version 0.8.2.
-
class
MenuItemElement
(loader, name)[source]¶ Bases:
twisted.web._element.Element
Helper class to render a menu entry for the main navigation bar, created with
MenuNavigationBar
.New in version 0.8.2.
Bases:
twisted.web._element.Element
Convenient class to create a dynamic navigation bar
New in version 0.8.2.
Note
This is strongly related with the file: templates/template_index.html. The content of the each element should be implemented dynamically (here or in any subclass) or statically (into the mentioned file).
-
class
DevicesWatcher
(page)[source]¶ Bases:
coherence.log.LogAble
To manage the connected devices. Broadcast messages informing about the connected/disconnected devices via the web socket interface. This messages can be received by the html/js side, which will be responsible to add or to remove the devices.
New in version 0.8.2.
-
addSlash
= False¶
-
isLeaf
= True¶
-
detected
= []¶
-
-
format_log
(message, *args, **kwargs)[source]¶ Simple method to format the captured logs.
- Parameters
- Returns
A formatted string including the args and the kwargs.
New in version 0.8.2.
-
class
LogsWatcher
(page, active)[source]¶ Bases:
coherence.log.LogAble
Object that takes control of all known loggers (at init time) and redirects them into the web-ui interface.
- Parameters
New in version 0.8.2.
-
logCategory
= 'webui-logger'¶
-
addSlash
= False¶
-
isLeaf
= True¶
-
_messages
= []¶
-
_ws_ready
= False¶
-
class
IndexResource
(web_resource)[source]¶ Bases:
twisted.web._element.Element
,coherence.log.LogAble
A sub class of
twisted.web.template.Element
which represents the main page for the web-ui interface. This takes care of rendering the main page as an element template, so we could add some dynamic elements when initializing it, like the navigation bar or the current version of the program.New in version 0.8.2.
-
loader
= <XMLFile of FilePath('/home/travis/build/opacam/Cohen3/coherence/web/templates/template_index.xml')>¶
-
-
class
Web
(coherence)[source]¶ Bases:
object
Convenient class describing an adapterFactory that allow us to register
registerAdapter
- Parameters
coherence – An instance of ~coherence.base.Coherence
-
class
WebUI
(coherence, *a, **kw)[source]¶ Bases:
twisted.web.resource.Resource
,coherence.log.LogAble
A convenient html interface to browse the connected devices via preferred web browser. This interface could be enabled when initializing
Coherence
by setting “‘web-ui’: ‘yes’” into your config command or via config file using the same key and value.- Parameters
coherence (object) – An instance of ~coherence.base.Coherence
Changed in version 0.8.2.
Warning
Be aware that the browser should support Web Sockets and to have js enabled. All modern browsers should have this features integrated (tested with firefox and google chrome).
-
logCategory
= 'webui'¶
-
addSlash
= True¶
-
isLeaf
= False¶
-
ws_recived
= []¶
-
render
(request)[source]¶ Render a given resource. See L{IResource}’s render method.
I delegate to methods of self with the form ‘render_METHOD’ where METHOD is the HTTP that was used to make the request. Examples: render_GET, render_HEAD, render_POST, and so on. Generally you should implement those methods instead of overriding this one.
render_METHOD methods are expected to return a byte string which will be the rendered page, unless the return value is C{server.NOT_DONE_YET}, in which case it is this class’s responsibility to write the results using C{request.write(data)} and then call C{request.finish()}.
Old code that overrides render() directly is likewise expected to return a byte string or NOT_DONE_YET.
@see: L{IResource.render}
-
getChild
(name, request)[source]¶ Retrieve a ‘child’ resource from me.
Implement this to create dynamic resource generation – resources which are always available may be registered with self.putChild().
This will not be called if the class-level variable ‘isLeaf’ is set in your subclass; instead, the ‘postpath’ attribute of the request will be left as a list of the remaining path elements.
For example, the URL /foo/bar/baz will normally be:
| site.resource.getChild('foo').getChild('bar').getChild('baz').
However, if the resource returned by ‘bar’ has isLeaf set to true, then the getChild call will never be made on it.
Parameters and return value have the same meaning and requirements as those defined by L{IResource.getChildWithDefault}.