Skip to content

Commit e19e1ac

Browse files
committed
[DOCUMENTATION]: Update demo and docs
1 parent 1e71801 commit e19e1ac

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

jaseci_serv/jaseci_serv/socket/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,68 @@
4040
##### **`HOW TO TRIGGER`**
4141
```js
4242
wb.notify(target, {"test": 123456});
43+
```
44+
45+
# **WEB SETUP**
46+
```js
47+
// target can be random string or current token
48+
socket = new WebSocket(`ws://${window.location.host}/ws/socket-server/{{target}}`)
49+
socket.onmessage = (event) => {
50+
console.log(event);
51+
// your event handler
52+
data = JSON.parse(event.data);
53+
switch(data.type) {
54+
case "connect":
55+
// code block
56+
break;
57+
case "your-custom-type":
58+
// code block
59+
break;
60+
default:
61+
// code block
62+
}
63+
}
64+
// notify backend
65+
socket.send(JSON.stringify({"message": "test"}))
66+
```
67+
## Example connection via `token`
68+
```js
69+
socket = new WebSocket(`ws://${window.location.host}/ws/socket-server/276a40aec1dffc48a25463c3e2545473b45a663364adf3a2f523b903aa254c9f`)
70+
// if token is valid, it's session will be connected to the user's master jid
71+
// all notification from FE will now be send to user's master jid
72+
73+
socket.onmessage = (event) => {
74+
console.log(event);
75+
}
76+
77+
// all clients that is subscribed to user's master jid will received this notification
78+
socket.send(JSON.stringify({"message": "test"}))
79+
```
80+
#### console.`log`(**event**)
81+
> ![console.log(event)](https://user-images.githubusercontent.com/74129725/267296913-b7b4bdd7-d6c7-49c2-82fe-2d19491daa6c.png "console.log(event)")
82+
#### event.`data`
83+
```txt
84+
{"type": "connect", "authenticated": true, "session_id": null}
85+
```
86+
---
87+
## Example connection **without** `token`
88+
```js
89+
socket = new WebSocket(`ws://${window.location.host}/ws/socket-server/any-ranmdom-string`)
90+
// this socket will be subscribed to a random uuid
91+
// you will need to use that random uuid on wb.notify as target params
92+
// FE is required to send it on walkers with wb.notify to override target
93+
94+
socket.onmessage = (event) => {
95+
console.log(event);
96+
// you may get session_id from JSON.parse(event.data).session_id
97+
}
98+
99+
// not advisable but still can be used for notifying that random uuid
100+
socket.send(JSON.stringify({"message": "test"}))
101+
```
102+
#### console.`log`(**event**)
103+
> ![console.log(event)](https://user-images.githubusercontent.com/74129725/267294795-032a7d78-0124-4db5-bed7-5858e7d72774.png "console.log(event)")
104+
#### event.`data`
105+
```txt
106+
{"type": "connect", "authenticated": false, "session_id": "53a0e05e-8689-4e87-984d-dbd4bad58c9d"}
43107
```

jaseci_serv/templates/examples/social_auth.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ <h1>Google Identity Services Authorization Token model</h1>
147147
{% endif %}
148148

149149
{% if provider == "google" %}
150-
socket = new WebSocket(`ws://${window.location.host}/ws/socket-server/276a40aec1dffc48a25463c3e2545473b45a663364adf3a2f523b903aa254c9f`)
150+
socket = new WebSocket(`ws://${window.location.host}/ws/socket-server/f8e9b218aff5e16b0b06f458dde7c15af9e77a3feb8b6d7ebbfa3e1da7ae7d63`)
151151
{% else %}
152152
socket = new WebSocket(`ws://${window.location.host}/ws/socket-server/anonymous`)
153153
{% endif %}
154154
socket.onmessage = (event) => {
155-
console.log(event)
155+
console.log(event);
156156
}
157157

158-
function notify-server() {
158+
function notify_server() {
159159
socket.send(JSON.stringify({"message": "test"}))
160160
}
161161

0 commit comments

Comments
 (0)