About
rbxwebhook.js is a fork and maintained version of @Reselim and her roblox-long-polling npm module. It allows you to communicate using events similar to BindableEvents. You are able to send events to your server and receive events. You also have the capabilities to send out events to all servers similar to MessagingService
How does it work?
This uses a long-polling (better explained by @Seranok in his blog post). It basically sends a request to your server and waits for a response instead of sending back a response immediately. It will send a request and wait 60 seconds for a response, if it does not get one within that time-frame it will abort the request and send another request right after it and do the exact same thing.
What are the Pros and Cons?
Pros
- Client and Server communication
- Simplistic
- Built into express to easily import to an already existing project.
Cons
- High in HTTP request budget
- Not great error handling
What is planned?
We have a few things planned in the future to ensure security and speed.
- Allow for @grilme99’s rocheck to be built right into the connection. (read more about it here)
- Better error handling.
Drawbacks for rocheck
- You need to create an maintain the account cookie to check
- There will not be any cookie refreshing (you will need to do that yourself, more about it here)
- Your place needs to be multiplayer (meaning more than 1 player able to join).
Example
View Example
Server
Main Script
// MainScript
var express = require("express")
var app = express();
app.use('/rbxwebhook', require(../PATH/TO/ROUTER/FILE))
app.get('/', (req, res) => {
res.send("Howdy")
});
app.listen(3000);
Router File
var longPolling = require("rbxwebhook.js");
var server = new longPolling();
server.on("connection", (conn) => {
console.log(`New connection (id: ${conn.id})`);
conn.on("ping", (message) => {
console.log(`echo: ${message}`);
conn.send("pong", message);
});
conn.on("broadcast", (message) => {
console.log(`broadcast: ${message}`);
server.broadcast("broadcast", message);
});
conn.on("disconnect", () => {
console.log(`${conn.id} disconnected`);
});
});
module.exports = server.router;
Client
local Connection = require(script.Connection)
local client = Connection.new()
client:connect("127.0.0.1:8080")
client:on("pong", function(message)
print("echoed from server: ", message)
end)
client:send("ping", "Hello world!")
game:BindToClose(function()
client:disconnect()
end)
I want to use it!
Great! Thanks for thinking about using rbxwebhook.js. Below is the link to the npm package.
To install it just run this in your terminal!
$ npm i -save rbxwebhook.js