0.0.25 • Published 5 months ago

@chet-cloud/server_push v0.0.25

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

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

  1. open the url to open a chatroot named marketing

    • https://ruapp-kiosk.azurewebsites.net/events?token=artisreit_2023_06_20&sub=marketing
  2. 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));
0.0.20

5 months ago

0.0.21

5 months ago

0.0.23

5 months ago

0.0.24

5 months ago

0.0.25

5 months ago

0.0.11

10 months ago

0.0.12

6 months ago

0.0.13

6 months ago

0.0.14

6 months ago

0.0.15

6 months ago

0.0.16

6 months ago

0.0.17

6 months ago

0.0.18

6 months ago

0.0.19

6 months ago

0.0.10

11 months ago

0.0.9

11 months ago

0.0.8

11 months ago

0.0.7

11 months ago

0.0.6

11 months ago

0.0.5

11 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago