Open vincentfretin opened 2 years ago
See https://github.com/networked-aframe/naf-janus-adapter/pull/15 if you want to play with the example I described.
The main issue I see is that the publisher (speaker) is receiving naf updates (u
, um
, r
messages) from all avatars from all rooms, this may be a big perf issue for the publisher if they publishes in 10 rooms with 20 avatars each. You can ignore on the client side the messages by setting NAF.options.syncSource="ignore-all"
(this is really a hack so it triggers this code path) but you're still receiving naf updates you don't need. The publisher won't see any avatars and so won't hear any participants in this case.
So the changes here may be interesting only with an alternative transport other than "datachannel" (which uses incoming_data
) or "websocket" (which uses process_data
) transports for the naf updates, like Phoenix channel that Hubs is using (here in hubs and here in reticulum) so the naf messages only broadcast to the room channel you're in (room "1" for example), but you can still broadcast the audio in other rooms by setting networked-scene room (room "1-2-3-4-5" to broadcast to rooms 1,2,3,4,5 for example)
While I'm thinking about it, I'm adding a note here. If you have some horizontal scaling implemented in your infra to scale the rooms on several janus instances, you need to make sure all the rooms 1,2,3,4,5 goes into the same janus instance.
After some thinking, some changes I may do to this PR:
room_ids
parameter for the MessageKind::Data
, if not specified broadcast to all rooms, otherwise broadcast to the specified rooms. Be careful on security, we still need to verify the user is really in those rooms.
(test some chat feature through the websocket transport, be sure that the speaker can choose to send a text message only to a single room or to all rooms)data_recipients_for
behavior used by incoming_data
to broadcast to all rooms instead of main room? In the end no I don't think it makes sense for some naf updates that shouldn't be broadcasted to several rooms. We can't easily do a filtering on room_id like we could for process_data.room_ids: [main_room]
in all naf messages when I'm in several rooms so we can only broadcast to a single room and not all rooms (This will be only used with the "websocket" transport.)process_data
, broadcast only if the occupant main room match the room_id given in parameter? Only for naf messages? So if \"dataType\":\"u\"
or {\"dataType\":\"um\"
or {\"dataType\":\"r\"
found in body string?
I rewrote @devfans changes against master https://github.com/mozilla/janus-plugin-sfu/issues/55#issuecomment-778065876 This includes the commit from #90. I will rebase once #90 is merged. This may not be the final implementation, maybe adding an additional message or modifying an existing message may be better. I post it as draft if anyone want to play with it.
To play with it, in the naf-janus-adapter repo
open in 3 different tabs:
In the browser console type the following:
First user is in room 1 and room 2:
Second user in room 1:
Third user in room 2:
So all availableOccupants and mediaStreams are what we expect. Avatars and properly hearing the audio of those avatars is another thing.
If second user (room 1 tab) connected after the first user (publisher in tab 12.html), issue this command for the first user
to force sending the entities (the avatar) to participants of main room (room 1), this will create the publisher avatar (and so the networked-audio-source) in room 1 tab.
Why the publisher avatar appears in room 1 tab when it connects after the others? Because the entities are sent with
this.syncAll(undefined, true);
on eachnetworked
component via theconnected
listener when the user connect. The other case where the entities are sent is when a datachannel open when we subscribe to a user, it callsthis.entities.completeSync(clientId, true)
that callssyncAll
on each entity, this is not the case here because the publisher subscribe to no one, this is why the publisher avatar doesn't appear if a participant goes into room 1 after the publisher.For room 2: We never see the first user (publisher) avatar (so no audio) because the naf updates doesn't go to room 2 (because we use datachannel transport and we have
&joined.room_ids[0]
indata_recipients_for
used byincoming_data
). The first user (publisher) mediastream is there though, you can listen to it:In 12.html tab, there are some strange things happening but explainable:
Now if we use websocket transport instead of datachannel. In the html files, add in adapter-ready listener:
instead of
incoming_data
, this will useprocess_data
that broadcasts naf updates to all rooms the publisher is in, so creating the publisher avatar in room 2 tab as well (the issue ofsyncAll
explained above still applies). But we still have the issue of ghost avatars in publisher room (12.html). This needs changes in naf-janus-adapter where we have the variousthis.room
checks. The publisher doesn't hear others, that's expected for performance but you may want to at least hear the users in the main room (room 1).So yeah here is the state of things. You will need changes in naf-janus-adapter and in your app to make use of this for a given use case. The function incoming_data should probably do the same thing that process_data to broadcasts to all rooms I think, it doesn't make sense that it's different, well it may depend of the use case. I don't have a clear use case myself for now. :)