@chet-cloud/server_push v0.0.25
Wait for message
curl http://localhost:8000/events?token=<TOKEN_SECRET>&sub=a
curl http://localhost:8000/events?token=<TOKEN_SECRET>&sub=b
Send message
curl -X POST -d 'hello' http://localhost:8000/events?token=<TOKEN_SECRET>&pub=a
curl -X POST -d 'hello' http://localhost:8000/events?token=<TOKEN_SECRET>&pub=b
Config in .env located in current work directory
TOKEN_SECRET=artisreit_2023_06_20
SERVER_PORT=8000
REDIS_ENDPOINT_URL=redis-13065.c56.east-us.azure.cloud.redislabs.com
REDIS_ENDPOINT_PORT=13065
REDIS_PASSWORD=xxxxxxxxxxxxxxxxxxxxxxxxxxx
REDIS_SUBSCRIBER_KEY=Server_push_redis_subscript_publish_key
example
- start server
npx @chet-cloud/server_push
- reqeust to subscript the a and b
curl 'http://localhost:8000/events?token=artisreit_2023_06_20&sub=a&sub=b&sub=c&sub=status' curl 'http://localhost:8000/events?token=artisreit_2023_06_20&sub=b'
- send a message to clients that subscript a
curl -X POST -d 'hello' 'http://localhost:8000/events?token=artisreit_2023_06_20&pub=a'
- send a message to clients that subscript b
curl -X POST -d 'world' 'http://localhost:8000/events?token=artisreit_2023_06_20&pub=b'
the build-in sub command status is used to subscribe all status of subscribe clients
curl 'http://localhost:8000/events?token=artisreit_2023_06_20&sub=status' ## output event: status data: [{"sessionId":"1701207747541Y3CKJGCc0eYdknTDp5qIdZmZss587P38","sub_set":["a","b","c","list"],"is_closed":true},{"sessionId":"1701207751146BYu54a7imcTaRgo7SKh3vJ7bArXmKq4I","sub_set":["list"],"is_closed":true},{"sessionId":"1701207775497mrS5pXIC8SENf2HJdjGvvCAxF7BMbZz1","sub_set":["a","b","c","status"]},{"sessionId":"17012077825699fGWd0eoIUAk8H2zEsZnk4MABnPioJB0","sub_set":["status"]},{"sessionId":"1701207819068IKJj8cDNqb07XMnSSvYcq7mINHDGmaQf","sub_set":["status"]}] id: 4
message filter
## will send message to client the subscribe b and sessionId is 1212 curl -X POST -d 'world' 'http://localhost:8000/events?token=artisreit_2023_06_20&pub=b&sessionId=1212'
or
open the url to open a chatroot named marketing
https://ruapp-kiosk.azurewebsites.net/events?token=artisreit_2023_06_20&sub=marketing
open the console of the chrome, send message "hello"
fetch('/events?token=artisreit_2023_06_20&pub=a', {method: 'POST', body: ` Hello, I am Chet `})
or
<script>
const eventSource = new EventSource('/events?token=artisreit_2023_06_20&sub=a&sub=b&sub=c',
{withCredentials: true});
eventSource.onopen = () => {
console.log('Connection to server established');
};
eventSource.onmessage = (event) => {
console.log('Received event:', event.data);
};
eventSource.onerror = (error) => {
console.error('An error occurred:', error);
};
eventSource.addEventListener("a",(d)=>{
console.log('Received data from event:[a]', event.data);
})
let i=0;
setInterval(() => {
fetch('/events?token=artisreit_2023_06_20&pub=a', {
method: 'POST',
body: "Hello world: " + (i++)
})
}, 2000);
</script>
For express usage:
import {createExpressServer} from '@chet-cloud/server_push'
app.use(createExpressServer(()=>true));
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
10 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago