Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/WebReflection/pocket.io
A minimalistic version of socket.io that weights about 1K instead of 60K.
https://github.com/WebReflection/pocket.io
Last synced: 5 days ago
JSON representation
A minimalistic version of socket.io that weights about 1K instead of 60K.
- Host: GitHub
- URL: https://github.com/WebReflection/pocket.io
- Owner: WebReflection
- License: isc
- Created: 2018-06-16T15:43:26.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-02-21T09:31:52.000Z (over 3 years ago)
- Last Synced: 2024-10-31T17:18:46.856Z (13 days ago)
- Language: JavaScript
- Homepage:
- Size: 16.6 KB
- Stars: 118
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
pocket.io
=========A minimalistic version of [socket.io](https://socket.io) that weights about 1K instead of 60K.
```html
$(function () {
var socket = io();
socket.on('connect', function () {
console.log(socket.id);
});
socket.on('chat message', function(msg){
$('#messages').append($('<li>').text(msg));
});
$('form').submit(function(){
socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
});
});```
On the Node.js side, you do the same you are doing now.
Try `node test/chat-express.js` and visit `localhost:3000` to see the classic chat demo working.
```js
var app = require('express')();
var http = require('http').Server(app);
var io = require('pocket.io')(http);app.get('/', function(req, res){
res.sendFile(__dirname + '/chat.html');
});io.on('connection', function(socket){
console.log('a user connected');
socket.on('chat message', function (msg) {
io.emit('chat message', msg);
});
socket.on('disconnect', function () {
console.log('disconnected');
});
});http.listen(3000, function(){
console.log('listening on *:3000');
});
```### API differences
You can specify a JSON like parser through the option.
As example, this is how you'd use recursion compatible serialization via the [flatted](https://github.com/WebReflection/flatted#flatted) module.
```js
// Node.js
io(server, {JSON: require('flatted/cjs')});// client, after having Flatted exposed somehow, i.e.
//
io({JSON: Flatted});
```