Skip to content

Commit

Permalink
Make serverURL optional, the default is /janus on the same domain (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentfretin committed Dec 15, 2024
1 parent fed73f0 commit 57fb242
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,23 @@ naf-janus-adapter should support anything that supports recent WebRTC standards
<a-scene networked-scene="
room: 1;
adapter: janus;
serverURL: wss://preprod-janus.example.com/janus;
">
</a-scene>
</body>
</html>
```

Default serverURL is `/janus` which is converted to `'wss://' + location.host + '/janus'`.
You can also specify a full url if the server is not the same:

```html
<a-scene networked-scene="
room: 1;
adapter: janus;
serverURL: wss://janus.example.com/janus;
">
```

Compared to other adapters like easyrtc, the janus adapter has a specific API,
you need to call `NAF.connection.adapter.setClientId` and
`NAF.connection.adapter.setLocalMediaStream`, see the [Audio example](examples/index.html)
Expand Down Expand Up @@ -88,9 +98,6 @@ scene.addEventListener('adapter-ready', ({ detail: adapter }) => {
- Build: `npm run build`
- Release: `npm run release`

For development on the same LAN with `npm start` and if you run the janus docker image locally, you can use the config
`serverURL: wss://192.168.1.15:8080/janus;` (change the ip by yours of course).

## Janus SFU deployment

- [How to deploy janus with the janus sfu plugin on Ubuntu 20.04](docs/janus-deployment.md)
Expand Down
1 change: 0 additions & 1 deletion examples/audio-with-camera.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
debug: false;
adapter: janus;
connectOnLoad: true;
serverURL: wss://preprod-janus.example.com/janus;
"
renderer="physicallyCorrectLights: true;"
>
Expand Down
7 changes: 3 additions & 4 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@
For development, networked-scene is configured with:
adapter: janus
serverURL: wss://192.168.1.15:8080/janus;
serverURL: /janus;
Run janus container locally:
cd janus-plugin-sfu/docker
docker compose up
cd naf-janus-adapter
npm start # to have https proxy on 8080 to janus http://127.0.0.1:8188/janus
npm start # to serve the examples and proxy /janus to http://127.0.0.1:8188/janus
go to https://192.168.1.15:8080
go to https://localhost:8080
-->
<a-scene
audio
Expand All @@ -78,7 +78,6 @@
debug: false;
adapter: janus;
connectOnLoad: true;
serverURL: wss://192.168.1.15:8080/janus;
"
renderer="physicallyCorrectLights: true;"
>
Expand Down
10 changes: 10 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ class JanusAdapter {
}

connect() {
if (this.serverUrl === '/') {
this.serverUrl = '/janus';
}
if (this.serverUrl === '/janus') {
if (location.protocol === 'https:') {
this.serverUrl = 'wss://' + location.host + '/janus';
} else {
this.serverUrl = 'ws://' + location.host + '/janus';
}
}
debug(`connecting to ${this.serverUrl}`);

const websocketConnection = new Promise((resolve, reject) => {
Expand Down

0 comments on commit 57fb242

Please sign in to comment.