Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/drulac/socket.io-with-get
socket.io superset to perform get request through websockets
https://github.com/drulac/socket.io-with-get
Last synced: about 15 hours ago
JSON representation
socket.io superset to perform get request through websockets
- Host: GitHub
- URL: https://github.com/drulac/socket.io-with-get
- Owner: Drulac
- License: gpl-3.0
- Created: 2017-02-19T14:56:16.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-11-20T16:18:00.000Z (almost 4 years ago)
- Last Synced: 2024-01-30T02:54:53.502Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 24.4 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# socket.io-with-GET
socket.io superset who allow you to perform get request through websockets
(for the browser you will find the code in [socket-with-get.js](./socket-with-get.js))use is really easy :
you can use it in the client :
```js
(async ()=>{
const socket = new Socket(io(':8080'));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");
})().catch(err=>{throw new Error(err)});
```
(you must include the socket.io source code before include our code) (or use native websocket with [socket-with-on](https://github.com/Drulac/uws-with-on))and this on the server :
```js
var io = require('socket.io')(8080);
var Socket = require('socket.io-with-get');io.on('connection', async function(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);
});
```