Repository navigation
Expand file tree
/
Copy pathWebSocketBackend.py
More file actions
64 lines (50 loc) · 2.13 KB
/
Copy pathWebSocketBackend.py
File metadata and controls
64 lines (50 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################
# Copyright(c) 2008-2012 pyLoad Team
# http://www.pyload.org
#
# This file is part of pyLoad.
# pyLoad is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Subjected to the terms and conditions in LICENSE
#
# @author: RaNaN
###############################################################################
import logging
from RemoteManager import BackendBase
from mod_pywebsocket import util
def get_class_logger(o=None):
return logging.getLogger('log')
# Monkey patch for our logger
util.get_class_logger = get_class_logger
class WebSocketBackend(BackendBase):
def setup(self, host, port):
from wsbackend.Server import WebSocketServer, DefaultOptions
from wsbackend.Dispatcher import Dispatcher
from wsbackend.ApiHandler import ApiHandler
from wsbackend.AsyncHandler import AsyncHandler
options = DefaultOptions()
options.server_host = host
options.port = port
options.dispatcher = Dispatcher()
options.dispatcher.addHandler(ApiHandler.PATH, ApiHandler(self.core.api))
options.dispatcher.addHandler(AsyncHandler.PATH, AsyncHandler(self.core.api))
# tls is needed when requested or webUI is also on tls
if self.core.api.isWSSecure():
from wsbackend.Server import import_ssl
tls_module = import_ssl()
if tls_module:
options.use_tls = True
options.tls_module = tls_module
options.certificate = self.core.config['ssl']['cert']
options.private_key = self.core.config['ssl']['key']
self.core.log.info(_('Using secure WebSocket'))
else:
self.core.log.warning(_('SSL could not be imported'))
self.server = WebSocketServer(options)
def serve(self):
self.server.serve_forever()