0.0.25 • Published 2 years ago

@chet-cloud/server_push v0.0.25

Weekly downloads
-
License
-
Repository
-
Last release
2 years 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

2 years ago

0.0.21

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

2 years ago

0.0.15

2 years ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago