Skip to content

Commit 52224ab

Browse files
added feature to support individual client communication
1 parent f9cc724 commit 52224ab

File tree

12 files changed

+3339
-218
lines changed

12 files changed

+3339
-218
lines changed

.idea/.gitignore

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jsLibraryMappings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/masonite-broadcast-client.iml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,44 +31,48 @@ $ yarn add masonite-broadcast-client socket.io-client
3131
**Example**
3232

3333
```js
34+
/** Connection */
35+
3436
window.io = require("socket.io-client");
3537
const MasoniteBroadcastClient = require("masonite-broadcast-client");
3638

37-
const socket = new MasoniteBroadcastClient({
38-
url: "http://localhost:3000",
39+
const broadcast = new MasoniteBroadcastClient({
40+
url: "http://localhost:3000",
41+
broadcastUrl: "http://localhost:8000/broadcast/auth" // optional
3942
});
4043

41-
socket.onUserConnected(user => {
42-
console.log(`${user.userID} connected`);
44+
broadcast.onUserConnected(user => {
45+
console.log(`${user.userID} connected`);
4346
});
47+
```
48+
```js
49+
/** You can add an extra value in session */
4450

51+
broadcast.setExtra("value", (user) => { // value here must not be complex data types
52+
console.log(user);
53+
})
54+
```
55+
```js
56+
/** Subscribe to channel */
4557

46-
const chat = socket.subscribe("chat");
47-
58+
const subscription = broadcast.subscribe("chat");
59+
```
60+
```js
4861
/** Broadcast to all */
49-
chat.emit("your-event", your_data_here)
5062

63+
subscription.emit("your-event", your_data_here)
64+
```
65+
```js
5166
/** Broadcast to all except the sender */
52-
chat.broadcast("your-event", your_data_here);
53-
54-
55-
const news = socket.subscribe("news");
56-
news.listen("highlights", (data) => {
57-
console.log(data);
58-
});
5967

68+
subscription.broadcast("your-event", your_data_here);
69+
```
70+
```js
71+
/** Listen for events */
6072

61-
channel.listen('message', (data) => {
73+
subscription.listen('message', (data) => {
6274
console.log(data);
6375
}).listen('your-event', (data) => {
6476
console.log(data);
65-
})...;
66-
67-
68-
/** You can add an extra value in session */
69-
socket.setExtra("value", (user) => { // value here must not be complex data types
70-
console.log(user);
71-
})
72-
73-
77+
});
7478
```

0 commit comments

Comments
 (0)