How networked-aframe/naf-janus-adapter works
Project type and purpose
• This is a front-end adapter library (an NPM package) for “networked-aframe,” enabling multi-user VR scenes by routing WebRTC media and data through a Janus SFU backend.
• It is not a standalone web application or server; instead it plugs into any A-Frame app that uses networked-aframe, replacing the default signaling/data layer with Janus.
File structure
• src/index.js: the adapter’s entry point.
• webpack.common.js / webpack.dev.js / webpack.prod.js: build pipelines producing the browser-ready bundle in dist/naf-janus-adapter.js.
• dist/: prebuilt UMD bundle for CDN/browser use.
• examples/: static HTML/JS/CSS demonstrating usage, including audio and video.
• docs/: deployment- and security-related markdown for Janus SFU.
• package.json: declares dependencies (networked-aframe, webrtc-adapter, etc.) and scripts (start, build, release).
README for additional insights
• Describes the adapter’s role: it registers itself on the NAF global, overrides connect(), getMediaStream(), syncOccupants(), etc.
• Outlines required external scripts: aframe.js, networked-aframe.js, webrtc-adapter shim.
• Mentions the two main flows: signaling (via Janus Data WebSockets) and media transport (WebRTC peer connections to the SFU).
Main components
a. Client-side components:
– A-Frame scene + networked-scene component
– networked-aframe core library (NAF)
– naf-janus-adapter plugin
– webrtc-adapter shim
b. External systems:
– Janus WebRTC Server (SFU)
– STUN/TURN servers (if configured)
c. Build pipeline (optional in high-level view):
– src/index.js → webpack → dist/naf-janus-adapter.js → published on npm or CDN
d. Example host environment:
– Static web server or any web host serving examples/index.html
Relationships and interactions
• On page load:
[A-Frame.js] → provides scene
[networked-aframe.js] → registers NAF global
[webrtc-adapter.js] → normalizes WebRTC APIs
[naf-janus-adapter.js] → registers adapter on NAF.connection.adapter
• When the scene’s networked-scene.connect() is invoked:
→ Adapter opens a WebSocket/WSS connection to Janus (serverURL)
→ Attaches to janus.plugin.videoroom plugin, joins a room
→ Exchanges SDP offers/answers and ICE candidates via Janus signaling channel
→ Once peer connections for desired occupants are established, the connect() Promise resolves
• Media flow:
Local microphone/camera stream → RTCPeerConnection → Janus SFU → SFU forwards streams to other participants → adapter delivers remote MediaStream tracks to NAF
Architectural patterns and design principles
• Adapter pattern: wraps Janus connection logic to conform to networked-aframe’s adapter API
• Plugin architecture: loose coupling—any WebRTC-capable back end can be used if it implements the same adapter methods (setClientId, setLocalMediaStream, connect, getMediaStream, syncOccupants, enableMicrophone, etc.)
• Promise-based asynchronous initialization for stronger flow control in client apps
• Separation of concerns:
– Build/config (webpack)
– Documentation and examples (docs/, examples/)
– Core logic (src/index.js)
Key details to capture
• The ordering of script includes in the HTML (webrtc-adapter → aframe → networked-aframe → naf-janus-adapter)
• The default serverURL resolution logic (/janus → 'wss://' + location.host + '/janus') and override option
• The distinction between data/signaling channel and media channel
• The optional consumption of video streams via getMediaStream(clientId, "video")