1.4.0 • Published 3 years ago

uws-with-on.js v1.4.0

Weekly downloads
1
License
GPL-3.0
Repository
github
Last release
3 years ago

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 superset too)

you can use it in the client :

<!doctype html>
<html>
<head>
	<title>.</title>
	<script src="../socketWithOn.js"></script>
	<script src="socket.io-with-get.js"></script>
</head>
<body>
	<script>
	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");
	};
	</script>
</body>
</html>

and this on the server :

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);
	}
});
1.4.0

3 years ago

1.3.0

4 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago