diff --git a/jaseci_core/jaseci/prim/ability.py b/jaseci_core/jaseci/prim/ability.py index c8186be36b..d785753d24 100644 --- a/jaseci_core/jaseci/prim/ability.py +++ b/jaseci_core/jaseci/prim/ability.py @@ -80,12 +80,6 @@ def run_action(self, param_list, scope, interp, jac_ast): else: try: result = func(*param_list["args"], **param_list["kwargs"]) - except TypeError as e: - params = str(inspect.signature(func)) - interp.rt_error( - f"Invalid arguments {param_list} to action call {self.name}! Valid paramters are {params}.", - jac_ast, - ) except Exception as e: interp.rt_error(e, jac_ast, True) t = time.time() - ts diff --git a/jaseci_serv/jaseci_serv/socket/consumer.py b/jaseci_serv/jaseci_serv/socket/consumer.py index 1fe4c63822..4fb18c4fb8 100644 --- a/jaseci_serv/jaseci_serv/socket/consumer.py +++ b/jaseci_serv/jaseci_serv/socket/consumer.py @@ -1,5 +1,5 @@ from json import loads, dumps -from .authentication import authenticated_user +from .event_action import authenticated_user from channels.generic.websocket import WebsocketConsumer from asgiref.sync import async_to_sync @@ -8,10 +8,14 @@ class SocketConsumer(WebsocketConsumer): def connect(self): self.accept() - user = authenticated_user(self.scope["url_route"]["kwargs"]["token"]) - self.master = user.master.urn[9:] + self.token = self.scope["url_route"]["kwargs"]["token"] + + user = authenticated_user(self.token) + if user: + self.token = user.master.urn[9:] + + async_to_sync(self.channel_layer.group_add)(self.token, self.channel_name) - async_to_sync(self.channel_layer.group_add)(self.master, self.channel_name) self.send( text_data=dumps({"type": "connection_established", "message": "Connected!"}) ) @@ -20,8 +24,8 @@ def receive(self, text_data=None, bytes_data=None): data = loads(text_data) async_to_sync(self.channel_layer.group_send)( - self.master, {"type": "testing", "message": data["message"]} + self.token, {"type": "notify", "data": data} ) - def testing(self, event): - self.send(text_data=dumps({"type": "test", "message": event["message"]})) + def notify(self, data): + self.send(text_data=dumps(data)) diff --git a/jaseci_serv/jaseci_serv/socket/authentication.py b/jaseci_serv/jaseci_serv/socket/event_action.py similarity index 65% rename from jaseci_serv/jaseci_serv/socket/authentication.py rename to jaseci_serv/jaseci_serv/socket/event_action.py index ddbeb1cf43..dcd2154d09 100644 --- a/jaseci_serv/jaseci_serv/socket/authentication.py +++ b/jaseci_serv/jaseci_serv/socket/event_action.py @@ -10,6 +10,9 @@ def compare_digest(a, b): from knox.crypto import hash_token from knox.models import AuthToken from knox.settings import CONSTANTS +from jaseci.jsorc.live_actions import jaseci_action +from channels.layers import get_channel_layer +from asgiref.sync import async_to_sync def authenticated_user(token: str): @@ -23,3 +26,10 @@ def authenticated_user(token: str): except (TypeError, binascii.Error): pass return None + + +@jaseci_action(act_group=["wb"]) +def notify(target: str, data: dict): + async_to_sync(get_channel_layer().group_send)( + target, {"type": "notify", "data": data} + ) diff --git a/jaseci_serv/templates/examples/social_auth.html b/jaseci_serv/templates/examples/social_auth.html index 014b3fa6dc..11b3615907 100644 --- a/jaseci_serv/templates/examples/social_auth.html +++ b/jaseci_serv/templates/examples/social_auth.html @@ -146,8 +146,11 @@

Google Identity Services Authorization Token model

{% endif %} {% endif %} -socket = new WebSocket(`ws://${window.location.host}/ws/socket-server/1e32585760f5b5cabcaa48cb953c59010ab29388c4e6d5acf301f939b5a1b80a`) - +{% if provider == "google" %} +socket = new WebSocket(`ws://${window.location.host}/ws/socket-server/d7a3050847ce1d863a2f74c5c57ee40819d97963199073b85de3ef2225604190`) +{% else %} +socket = new WebSocket(`ws://${window.location.host}/ws/socket-server/123456`) +{% endif %} socket.onmessage = (event) => { console.log(event) }