https://github.com/fibjs/fib-push
https://github.com/fibjs/fib-push
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/fibjs/fib-push
- Owner: fibjs
- Created: 2017-12-11T14:20:51.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-05-25T13:17:14.000Z (about 6 years ago)
- Last Synced: 2025-08-09T06:21:18.024Z (11 months ago)
- Language: TypeScript
- Size: 40 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
Awesome Lists containing this project
README
## fib-push
[](https://www.npmjs.org/package/fib-push)
[](https://travis-ci.org/fibjs/fib-push)
[](https://ci.appveyor.com/project/richardo2016/fib-push)
`fib-push` is one global service in a fibjs runtime, which provides duplex communication based on **websocket-like** connection, and manage end-2-end connection & **message queue** with **Channel**. One global service is enough in most cases, so we **don't** support multiple instances of `fib-push` at now.
`fib-push` has so less code that you could learn about its mechanism and usage just by reading source code :)
### Core Concept
- `Channel` is the pivot structure in `fib-push`.
- There is one global `idles` variable for recording idle channel, when new idle channel added as tail, the head one would be delete and removed.
- All message transmission is on json-encoded-format.
### Usage
```javascript
const push = require('fib-push');
push.config({
idle_limit: 10,
msg_limit: 10
});
var r = [];
var ws = {
send: m => r.push(m)
};
function filter_data (data) {
return data.foo === 'bar';
}
// mount one channel named of 'channel_name'
push.on('channel_name', ws, new Date(), filter_data);
push.post('channel_name', { foo: '_bar' })
console.log(r.length) // 0
push.post('channel_name', { foo: 'bar' })
console.log(r.length) // 1
console.log(r[0]) // {"timestamp":"2018-05-11T09:18:05.134Z","ch":"channel_name","data":{"foo":"bar"}}
console.log(JSON.parse(r[0]).data) // {foo: 'bar'}
```
View more useages in this repo's `test/*.js`
---
### Types
View details in [@types]
---
[Link]:docs/link.md
[@types]:@types/index.d.ts