Skip to content

uws superset who allow you to listen on event like with socket.io

License

Notifications You must be signed in to change notification settings

Drulac/uws-with-on

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

uws superset who allow you to listen on event like with socket.io

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published