I’m about to setup my own server for networking. I noticed the docs point to: Glitch :・゚✧
but I saw a recent forum post here where @marcel mentioned using: Glitch :・゚✧
The biggest difference seems to be Fastify vs Express. Which would be the best starting point to reference when rolling my own server?
Original Post on Discord
by user 300386587278049291
Changed the channel name: needle-starter vs needle-server for networking?
by user 300386587278049291
marcel
(marwi)
March 1, 2023, 12:00am
3
The first url is an older glitch version which is not maintained anymore. Express or fastify dont really matter, the networking package that is used in the tiny-starter has implementations for both. The main chunk is in src but as said the glitch version is not maintained and a bit behind.
When rolling your own server I think what you’re asking is about hosting the backend somewhere else and not on glitch. Do I understand you correctly or is that not what you want?
marcel
(marwi)
March 1, 2023, 12:00am
4
Which docs page does point to the glitch url above? It should be updated
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development, and can be deployed anywhere. It is flexible, extensible, and collaboration and XR come naturally. Needle Exporter for Unity bridges the Unity Editor and the...
by user 300386587278049291
Yes I want to host elsewhere outside of Glitch
by user 300386587278049291
marcel
(marwi)
March 1, 2023, 12:00am
7
Ok you can most easily host either a fastify or express app and then setup the websocket endpoint like so:
const networking = require("@needle-tools/needle-tiny-networking-ws");
networking.startServerExpress(app, { endpoint: "/ws" });
or for fastify (you can find that in the glitch starter server.js file)
If you want you can add a little bit of code for other frameworks. Here’s a snipped of what it does internally as a reference:
module.exports.startServerFastify = function (fastify, options) {
const networking = create(fastify, options);
fastify.register(require('fastify-websocket'));
const endpoint = getEndpoint(options)
console.log("Using endpoint", endpoint);
fastify.get(endpoint, { websocket: true }, (connection, req) => {
const proxy = new FastifyProxy(connection);
networking.onConnection(proxy);
})
return networking;
};
function getEndpoint(options) {
if (options && options.endpoint !== undefined && typeof options.endpoint === "string") {
return options.endpoint;
}
return "/";
}
function create(app, options) {
console.info("Starting networking server");
const networking = require("./networking");
networking.init(app, options);
return networking;
}
The fastify proxy just implemets this bit of code:
class Proxy {
on(name, callback) {
}
send(key, value) {
}
}
module.exports.Proxy = Proxy;
But as said: for fastify and express you can just call the methods that are already exported and optionally provide an endpoint url in the options object.
Do you think that helps you getting started? Where do you want to host and what server framework are you planning to use?
Yes that helps! Thank for as always for the super prompt response. How do you guys get any work done being so good with support?
by user 300386587278049291
I’ve never used Fastify, I think I’ll give that a try
by user 300386587278049291
as far as where…I’m not sure. Going to get it going locally and then will likely spin up something on AWS or similar
by user 300386587278049291
I noticed the room names (secretKey) are configured in deploy.js on glitch. So is the room system (and therefore SynchedRoom component) outside your networking library? I will need to implement that on my own?
by user 300386587278049291
marcel
(marwi)
March 1, 2023, 12:00am
12
No everything networked goes through rooms. They are at the core of the networking package
marcel
(marwi)
March 1, 2023, 12:00am
13
All the SyncedRoom component does is generate a room name (or use the one you give it via the url) and then requests to join that room
Ok got it - thanks again!
by user 300386587278049291