这是indexloc提供的服务,不要输入任何密码
Skip to content

Add uws adapter and server #483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 14, 2024
Merged

Add uws adapter and server #483

merged 4 commits into from
Dec 14, 2024

Conversation

vincentfretin
Copy link
Member

Add uws adapter, equivalent of the socketio adapter but using WebSocket directly and with the reconnection logic from the janus adapter.
You can easily compare src/adapters/naf-socketio-adapter.js and src/adapters/naf-uws-adapter.js if you're interested in the implementation.

Add the uws server based on https://github.com/uNetworking/uWebSockets.js
see comments in the server/uws-server.cjs if you're interested in running it. This is the exact equivalent of server/socketio-server.cjs that includes room instancing.

On Raspberry Pi 400, 70 moving users with socketio were taking 100% of cpu, with uws server only 30%.
https://x.com/vincentfretin/status/1866053292972822729

@vincentfretin vincentfretin self-assigned this Dec 14, 2024
@vincentfretin vincentfretin merged commit 58352df into master Dec 14, 2024
1 check passed
@vincentfretin vincentfretin deleted the uws-adapter branch December 14, 2024 15:02
@vincentfretin
Copy link
Member Author

See comments in the server/uws-server.cjs file. Best is to use https directly on nodejs, but you can still put the node server behind nginx if you need.

To run the server:

git clone git@github.com:networked-aframe/networked-aframe.git
cd networked-aframe
npx webpack serve --server-type https
// and stop it with ctrl+c, it will generate the file node_modules/.cache/webpack-dev-server/server.pem
npm install uNetworking/uWebSockets.js#v20.51.0
node server/uws-server.cjs

The uws adapter is included in the 0.13.0 release, use this in your index.html:

<html>
  <head>
    <title>My Networked-Aframe Scene</title>
    <script src="https://aframe.io/releases/1.6.0/aframe.min.js"></script>
    <script src="https://unpkg.com/networked-aframe@^0.13.0/dist/networked-aframe.min.js"></script>
  </head>
  <body>
    <a-scene
      networked-scene="
        room: basic;
        debug: false;
        adapter: uws;
        connectOnLoad: true;
      "
    >

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant