Mercurial > libervia-web
annotate libervia.tac @ 35:d43d6e4b9dc8
room user joining/leaving
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 16 May 2011 18:19:35 +0200 |
parents | 7684e3ceb12d |
children | 1d406077b49b |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 Libervia: a Salut à Toi frontend | |
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) | |
7 | |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU Affero General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU Affero General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU Affero General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 from twisted.application import internet, service | |
23 from twisted.internet import glib2reactor | |
24 glib2reactor.install() | |
25 from twisted.internet import reactor, defer | |
26 | |
27 from twisted.web import server | |
28 from twisted.web import error as weberror | |
29 from twisted.web.static import File | |
30 from twisted.web.resource import Resource | |
10 | 31 from twisted.words.protocols.jabber.jid import JID |
0 | 32 from txjsonrpc.web import jsonrpc |
33 from txjsonrpc import jsonrpclib | |
34 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService | |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
35 import re |
10 | 36 from server_side.blog import MicroBlog |
37 | |
0 | 38 TIMEOUT = 120 #Session's time out, after that the user will be disconnected |
39 | |
40 | |
41 class MethodHandler(jsonrpc.JSONRPC): | |
42 | |
43 def __init__(self, sat_host): | |
44 jsonrpc.JSONRPC.__init__(self) | |
45 self.sat_host=sat_host | |
46 | |
47 def render(self, request): | |
1 | 48 self.session = request.getSession() |
0 | 49 try: |
1 | 50 profile = self.session.sat_profile |
0 | 51 except AttributeError: |
52 #user is not identified, we return a jsonrpc fault | |
53 parsed = jsonrpclib.loads(request.content.read()) | |
54 fault = jsonrpclib.Fault(0, "Not allowed") #FIXME: define some standard error codes for libervia | |
55 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) | |
56 return jsonrpc.JSONRPC.render(self, request) | |
19 | 57 |
58 def jsonrpc_getProfileJid(self): | |
59 """Return the jid of the profile""" | |
60 profile = self.session.sat_profile | |
61 self.session.sat_jid = self.sat_host.bridge.getParamA("JabberID", "Connection", profile_key=profile) | |
62 return self.session.sat_jid | |
0 | 63 |
64 def jsonrpc_getContacts(self): | |
65 """Return all passed args.""" | |
1 | 66 profile = self.session.sat_profile |
67 return self.sat_host.bridge.getContacts(profile) | |
20 | 68 |
69 def jsonrpc_setStatus(self, status): | |
70 """Change the status""" | |
71 profile = self.session.sat_profile | |
72 print "new status received:", status | |
73 self.sat_host.bridge.setPresence('', '', 0, {'':status}, profile) | |
74 | |
19 | 75 |
76 def jsonrpc_sendMessage(self, to_jid, msg, subject, type): | |
77 """send message""" | |
78 profile = self.session.sat_profile | |
79 return self.sat_host.bridge.sendMessage(to_jid, msg, subject, type, profile) | |
0 | 80 |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
81 def jsonrpc_sendMblog(self, raw_text): |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
82 """Parse raw_text of the microblog box, and send message consequently""" |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
83 profile = self.session.sat_profile |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
84 match = re.match(r'@(.+?): *(.*$)', raw_text) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
85 if match: |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
86 recip = match.group(1) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
87 text = match.group(2) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
88 if recip == '@' and text: |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
89 #This text if for the public microblog |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
90 print "Sending message to everybody" |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
91 return self.sat_host.bridge.sendPersonalEvent("MICROBLOG", {'content':text}, profile) |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
92 else: |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
93 return self.sat_host.bridge.sendGroupBlog([recip], text, profile) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
94 |
20 | 95 def jsonrpc_getPresenceStatus(self): |
96 """Get Presence information for connected contacts""" | |
97 profile = self.session.sat_profile | |
98 return self.sat_host.bridge.getPresenceStatus(profile) | |
99 | |
19 | 100 def jsonrpc_getHistory(self, from_jid, to_jid, size): |
101 """Return history for the from_jid/to_jid couple""" | |
102 #FIXME: this method should definitely be asynchrone, need to fix it !!! | |
103 profile = self.session.sat_profile | |
104 try: | |
105 _jid = JID(self.session.sat_jid) | |
106 except: | |
107 error("No jid saved for this profile") | |
108 return {} | |
109 if JID(from_jid).userhost() != _jid.userhost() and JID(to_jid) != _jid.userhost(): | |
110 error("Trying to get history from a different jid, maybe a hack attempt ?") | |
111 return {} | |
24 | 112 return self.sat_host.bridge.getHistory(from_jid, to_jid, size) |
19 | 113 |
30
7684e3ceb12d
server_side: added getRoomJoined method
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
114 def jsonrpc_getRoomJoined(self): |
7684e3ceb12d
server_side: added getRoomJoined method
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
115 """Return list of room already joined by user""" |
7684e3ceb12d
server_side: added getRoomJoined method
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
116 profile = self.session.sat_profile |
7684e3ceb12d
server_side: added getRoomJoined method
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
117 return self.sat_host.bridge.getRoomJoined(profile) |
7684e3ceb12d
server_side: added getRoomJoined method
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
118 |
24 | 119 def jsonrpc_launchTarotGame(self, other_players): |
120 """Create a room, invite the other players and start a Tarot game""" | |
121 profile = self.session.sat_profile | |
122 self.sat_host.bridge.tarotGameLaunch(other_players, profile) | |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
123 |
0 | 124 class Register(jsonrpc.JSONRPC): |
125 """This class manage the registration procedure with SàT | |
126 It provide an api for the browser, check password and setup the web server""" | |
127 | |
128 def __init__(self, sat_host): | |
129 jsonrpc.JSONRPC.__init__(self) | |
130 self.sat_host=sat_host | |
131 self.profiles_waiting={} | |
132 self.request=None | |
133 | |
134 def getWaitingRequest(self, profile): | |
135 """Tell if a profile is trying to log in""" | |
136 if self.profiles_waiting.has_key(profile): | |
137 return self.profiles_waiting[profile] | |
138 else: | |
139 return None | |
140 | |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
141 def _fillMblogNodes(self, result, session): |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
142 """Fill the microblog nodes association for this session""" |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
143 print "Filling session for %s with %s" % (session.sat_profile, result) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
144 session.sat_mblog_nodes = dict(result) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
145 |
0 | 146 def render(self, request): |
147 """ | |
148 Render method with some hacks: | |
149 - if login is requested, try to login with form data | |
150 - except login, every method is jsonrpc | |
151 - user doesn't need to be authentified for isRegistered, but must be for all other methods | |
152 """ | |
153 if request.postpath==['login']: | |
154 return self.login(request) | |
155 _session = request.getSession() | |
156 parsed = jsonrpclib.loads(request.content.read()) | |
157 if parsed.get("method")!="isRegistered": | |
158 #if we don't call login or isRegistered, we need to be identified | |
159 try: | |
160 profile = _session.sat_profile | |
161 except AttributeError: | |
162 #user is not identified, we return a jsonrpc fault | |
163 fault = jsonrpclib.Fault(0, "Not allowed") #FIXME: define some standard error codes for libervia | |
164 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) | |
165 self.request = request | |
166 return jsonrpc.JSONRPC.render(self, request) | |
167 | |
168 def login(self, request): | |
169 """ | |
170 this method is called with the POST information from the registering form | |
171 it test if the password is ok, and log in if it's the case, | |
172 else it return an error | |
173 @param request: request of the register formulaire, must have "login" and "password" as arguments | |
174 @return: A constant indicating the state: | |
175 - BAD REQUEST: something is wrong in the request (bad arguments, profile_key for login) | |
176 - AUTH ERROR: either the profile or the password is wrong | |
177 - ALREADY WAITING: a request has already be made for this profile | |
178 - server.NOT_DONE_YET: the profile is being processed, the return value will be given by self._logged or self._logginError | |
179 """ | |
180 try: | |
181 _login = request.args['login'][0] | |
182 if _login.startswith('@'): | |
183 raise Exception('No profile_key allowed') | |
184 _pass = request.args['password'][0] | |
185 except KeyError: | |
186 return "BAD REQUEST" | |
187 | |
188 _profile_check = self.sat_host.bridge.getProfileName(_login) | |
189 _profile_pass = self.sat_host.bridge.getParamA("Password", "Connection", profile_key=_login) | |
190 | |
191 if not _profile_check or _profile_check != _login or _profile_pass != _pass: | |
192 return "AUTH ERROR" | |
193 | |
194 if self.profiles_waiting.has_key(_login): | |
195 return "ALREADY WAITING" | |
196 | |
197 if self.sat_host.bridge.isConnected(_login): | |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
198 return self._logged(_login, request, finish=False) |
0 | 199 |
200 self.profiles_waiting[_login] = request | |
201 self.sat_host.bridge.connect(_login) | |
202 return server.NOT_DONE_YET | |
203 | |
204 def __cleanWaiting(self, login): | |
205 """Remove login from waiting queue""" | |
206 try: | |
207 del self.profiles_waiting[login] | |
208 except KeyError: | |
209 pass | |
210 | |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
211 def _logged(self, profile, request, finish=True): |
0 | 212 """Set everything when a user just logged |
213 and return "LOGGED" to the requester""" | |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
214 self.__cleanWaiting(profile) |
0 | 215 _session = request.getSession() |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
216 _session.sat_profile = profile |
24 | 217 self.sat_host.prof_connected.add(profile) |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
218 d = defer.Deferred() |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
219 self.sat_host.bridge.getMblogNodes(profile, d.callback, d.errback) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
220 d.addCallback(self._fillMblogNodes, _session) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
221 if finish: |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
222 request.write('LOGGED') |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
223 request.finish() |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
224 else: |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
225 return "LOGGED" |
0 | 226 |
227 def _logginError(self, login, request, error_type): | |
228 """Something went wrong during loggin, return an error""" | |
229 self.__cleanWaiting(login) | |
230 return error_type | |
231 | |
232 def jsonrpc_isConnected(self): | |
233 _session = self.request.getSession() | |
234 profile = _session.sat_profile | |
235 return self.sat_host.bridge.isConnected(profile) | |
236 | |
237 def jsonrpc_connect(self): | |
238 _session = self.request.getSession() | |
239 profile = _session.sat_profile | |
240 if self.profiles_waiting.has_key(profile): | |
241 raise jsonrpclib.Fault('1','Already waiting') #FIXME: define some standard error codes for libervia | |
242 self.profiles_waiting[profile] = self.request | |
243 self.sat_host.bridge.connect(profile) | |
244 return server.NOT_DONE_YET | |
245 | |
246 def jsonrpc_isRegistered(self): | |
247 """Tell if the user is already registered""" | |
248 _session = self.request.getSession() | |
249 try: | |
250 profile = _session.sat_profile | |
251 except AttributeError: | |
252 return False | |
253 return True | |
254 | |
255 class SignalHandler(jsonrpc.JSONRPC): | |
256 | |
257 def __init__(self, sat_host): | |
258 Resource.__init__(self) | |
259 self.register=None | |
260 self.sat_host=sat_host | |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
261 self.signalDeferred = {} |
24 | 262 self.queue = {} #XXX: gof: don't forgot to purge queue on session end |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
263 |
0 | 264 def plugRegister(self, register): |
265 self.register = register | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
266 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
267 def jsonrpc_getSignals(self): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
268 """Keep the connection alive until a signal is received, then send it |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
269 @return: (signal, *signal_args)""" |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
270 _session = self.request.getSession() |
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
271 profile = _session.sat_profile |
24 | 272 if profile in self.queue: #if we have signals to send in queue |
273 if self.queue[profile]: | |
274 return self.queue[profile].pop(0) | |
275 else: | |
276 #the queue is empty, we delete the profile from queue | |
277 del self.queue[profile] | |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
278 self.signalDeferred[profile] = defer.Deferred() |
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
279 return self.signalDeferred[profile] |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
280 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
281 def getGenericCb(self, function_name): |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
282 """Return a generic function which send all params to signalDeferred.callback |
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
283 function must have profile as last argument""" |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
284 def genericCb(*args): |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
285 profile = args[-1] |
24 | 286 if not profile in self.sat_host.prof_connected: |
287 return | |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
288 if profile in self.signalDeferred: |
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
289 self.signalDeferred[profile].callback((function_name,args[:-1])) |
24 | 290 del self.signalDeferred[profile] |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
291 else: |
24 | 292 if not self.queue.has_key(profile): |
293 self.queue[profile] = [] | |
294 self.queue[profile].append((function_name, args[:-1])) | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
295 return genericCb |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
296 |
0 | 297 def connected(self, profile): |
298 assert(self.register) #register must be plugged | |
299 request = self.register.getWaitingRequest(profile) | |
300 if request: | |
301 self.register._logged(profile, request) | |
302 | |
303 def connectionError(self, error_type, profile): | |
304 assert(self.register) #register must be plugged | |
305 request = self.register.getWaitingRequest(profile) | |
306 if request: #The user is trying to log in | |
307 if error_type == "AUTH_ERROR": | |
308 _error_t = "AUTH ERROR" | |
309 else: | |
310 _error_t = "UNKNOWN" | |
311 self.register._logginError(profile, request, _error_t) | |
312 | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
313 def render(self, request): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
314 """ |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
315 Render method wich reject access if user is not identified |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
316 """ |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
317 _session = request.getSession() |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
318 parsed = jsonrpclib.loads(request.content.read()) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
319 try: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
320 profile = _session.sat_profile |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
321 except AttributeError: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
322 #user is not identified, we return a jsonrpc fault |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
323 fault = jsonrpclib.Fault(0, "Not allowed") #FIXME: define some standard error codes for libervia |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
324 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
325 self.request = request |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
326 return jsonrpc.JSONRPC.render(self, request) |
0 | 327 |
10 | 328 |
0 | 329 class Libervia(service.Service): |
330 | |
331 def __init__(self): | |
332 root = File("output/") | |
333 self.signal_handler = SignalHandler(self) | |
334 _register = Register(self) | |
335 self.signal_handler.plugRegister(_register) | |
336 self.sessions = {} #key = session value = user | |
24 | 337 self.prof_connected = set() #Profiles connected |
0 | 338 ## bridge ## |
339 try: | |
340 self.bridge=DBusBridgeFrontend() | |
341 except BridgeExceptionNoService: | |
342 print(u"Can't connect to SàT backend, are you sure it's launched ?") | |
343 import sys | |
344 sys.exit(1) | |
345 self.bridge.register("connected", self.signal_handler.connected) | |
346 self.bridge.register("connectionError", self.signal_handler.connectionError) | |
35 | 347 for signal_name in ['presenceUpdate', 'personalEvent', 'newMessage', 'roomJoined', 'roomUserJoined', 'roomUserLeft']: |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
348 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) |
10 | 349 root.putChild('json_signal_api', self.signal_handler) |
350 root.putChild('json_api', MethodHandler(self)) | |
351 root.putChild('register_api', _register) | |
352 root.putChild('blog', MicroBlog(self)) | |
353 root.putChild('css', File("server_css/")) | |
354 self.site = server.Site(root) | |
0 | 355 |
356 def startService(self): | |
357 reactor.listenTCP(8080, self.site) | |
1 | 358 |
0 | 359 def run(self): |
360 reactor.run() | |
361 | |
362 def stop(self): | |
363 reactor.stop() | |
364 | |
365 | |
366 | |
367 application = service.Application('Libervia') | |
368 service = Libervia() | |
369 service.setServiceParent(application) |