Skip to content

Commit e51b2e0

Browse files
author
Joel Collins
committed
Add views with websocket methods to LabThing.sockets
1 parent 9d3b759 commit e51b2e0

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/labthings/labthing.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ def init_app(self, app):
236236
# Custom JSON encoder
237237
app.json_encoder = self.json_encoder
238238

239+
# Create socket handler
240+
self.sockets = Sockets(app)
241+
239242
# Add resources, if registered before tying to a Flask app
240243
if len(self.views) > 0:
241244
for resource, urls, endpoint, kwargs in self.views:
@@ -244,8 +247,7 @@ def init_app(self, app):
244247
# Create base routes
245248
self._create_base_routes()
246249

247-
# Create socket handler
248-
self.sockets = Sockets(app)
250+
# Create base sockets
249251
self._create_base_sockets()
250252

251253
# Create base events
@@ -448,7 +450,13 @@ def _register_view(self, app, view, *urls, endpoint=None, **kwargs):
448450
# If we've got no Blueprint, just build a url with no prefix
449451
rule = self._complete_url(url, "")
450452
# Add the url to the application or blueprint
451-
app.add_url_rule(rule, view_func=resource_func, **kwargs)
453+
app.add_url_rule(rule, view_func=resource_func, endpoint=endpoint, **kwargs)
454+
# Add to self.sockets so that the socket middleware may
455+
# intercept the connection
456+
if hasattr(view, "websocket"):
457+
self.sockets.add_url_rule(
458+
rule, view_func=resource_func, endpoint=endpoint
459+
)
452460

453461
# There might be a better way to do this than _rules_by_endpoint,
454462
# but I can't find one so this will do for now. Skipping PYL-W0212

0 commit comments

Comments
 (0)