vercelsocket
v2.1.0
Published
A vercel socket software
Downloads
14
Readme
vercelsocket
A socket package for vercel
How to use
Install package with npm
npm install vercelsocket
Embed by using
Server:
const app = require("express")()
const io = require("vercelsocket")(app)
// Your code
app.listen(3000) // 3000 = Port
Client:
<html>
<body>
</body>
<script src="/socket/js">
</script>
<script>
io().then((socket) => {
window.onbeforeunload = () => {
socket.send("disconnect", "")
}
// Your script
})
</script>
</html>
As the program uses
app.get("route", callback)
no further action is needed.
Use it in applications
There are 2 actions:
io.bindto(eventname, function(data) {
// Callback
})
// and
io.send(eventname, data)
Clients are working like this:
<html>
<body>
</body>
<script src="/socket/js">
</script>
<script>
io().then((socket) => {
window.onbeforeunload = () => {
socket.send("disconnect", "")
}
socket.send("eventname", data)
socket.bindto("eventname", function(data) {
// Callback
})
})
</script>
</html>