Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/drulac/uws-with-on
uws superset who allow you to listen on event like with socket.io
https://github.com/drulac/uws-with-on
Last synced: about 14 hours ago
JSON representation
uws superset who allow you to listen on event like with socket.io
- Host: GitHub
- URL: https://github.com/drulac/uws-with-on
- Owner: Drulac
- License: gpl-3.0
- Created: 2017-09-01T21:32:30.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-11-20T16:30:42.000Z (almost 4 years ago)
- Last Synced: 2024-09-24T12:47:47.651Z (about 2 months ago)
- Language: JavaScript
- Size: 28.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# uws-with-on
uws superset who allow you to listen on event like with socket.io
(the code source work both in the browser and in NodeJS)use is really easy :
(these sample uses the [socket.io-with-get.js](https://github.com/Drulac/socket.io-with-GET) superset too)you can use it in the client :
```html.
var socket = new WebSocket("ws://localhost:5000");socket.onopen = async function (event) {
socket = new SocketWithOn(socket);
socket = new Socket(socket);socket.on('name', async (data)=>{
return "My name is Jhon... Jhon Doe...";
});let data = await socket.get("ping", {start: new Date().getTime()}).catch(err=>{throw new Error(err)});
let pingTime = new Date().getTime() - data.start;console.log(pingTime+" ms");
};
```
and this on the server :
```js
const WebSocketServer = require('uws').Server;
const SocketWithOn = require('uws-with-on.js');
const Socket = require('socket.io-with-get');
const wss = new WebSocketServer({ port: 5000 });wss.on('connection', async function(socket) {
try{
socket = new SocketWithOn(socket);
socket = new Socket(socket);socket.on('ping',async (data)=>{
return data;
});let data = await socket.get("name", {}).catch(err=>{throw new Error(err)});
console.log(data);
}catch(e){
console.log(e);
}
});