Skip to content

Commit

Permalink
temporary
Browse files Browse the repository at this point in the history
  • Loading branch information
amadolid committed Aug 9, 2023
1 parent 7741557 commit 4239e1c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
6 changes: 0 additions & 6 deletions jaseci_core/jaseci/prim/ability.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions jaseci_serv/jaseci_serv/socket/consumer.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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!"})
)
Expand All @@ -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))
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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}
)
7 changes: 5 additions & 2 deletions jaseci_serv/templates/examples/social_auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ <h1>Google Identity Services Authorization Token model</h1>
{% 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)
}
Expand Down

0 comments on commit 4239e1c

Please sign in to comment.