Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aneldev/dyna-node-channels
https://github.com/aneldev/dyna-node-channels
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/aneldev/dyna-node-channels
- Owner: aneldev
- License: mit
- Created: 2019-12-17T19:43:19.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-11T17:35:03.000Z (almost 2 years ago)
- Last Synced: 2024-10-13T13:39:41.599Z (about 1 month ago)
- Language: TypeScript
- Size: 1.35 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 21
-
Metadata Files:
- Readme: README.final.md
- License: LICENSE
Awesome Lists containing this project
README
# About
Create Channels and let the receivers to get stream data on real time.
# Example
The channels service
```
const channelsService = new DynaNodeChannelsService({
disk: createRam(),
serviceRegistration: {
encryptionKey: 'encryptionKey',
accessKey: 'accessKey',
serverDynaNodeAddress: 'n/localhost/33044',
serviceConnectionId: 'feeder-service',
},
onChannelRegister: async (channel, accessToken) => accessToken === '####at-registration',
onChannelPost: async (channel, accessToken) => accessToken === '####at-post',
onMessageQueueError: e => console.error(e),
onServiceRegistrationFail: e => console.error(e),
});
await channelsService.start();```
Create a broadcaster instance that will push messages to the channel
```
broadcaster = new DynaNodeChannelBroadcaster({
dynaNodeChannelServiceAddress: 'feeder-service@n/localhost/33044',
channel: 'footballGame',
accessToken: '####at-post',
});
```and send messages to the channel like this:
```
broadcaster.send({
command: 'football-game-score--update',
data: { host: 2, visitor: 0 }
})
```And this is the receiver that will receive the messages
```
const receiver = new DynaNodeChannelReceiver({
dynaNodeChannelServiceAddress: 'feeder-service@n/localhost/33044',
channel: 'footballGame',
accessToken: '####at-registration',
onMessage: message => {
const {
data: { // here we have the data posted to the channel
host,
visitor,
},
} = message;
}
});
receiver.start();
```