Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Gate camera and screen sharing on separate group settings (#43307)

Rafael dos Santos Silva7c45a3112355
diff --git a/db/structure.sql b/db/structure.sql
index 4bd95ea7498..a192b8347e8 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -25590,6 +25590,7 @@ ALTER TABLE ONLY public.ad_plugin_house_ads_groups
SET search_path TO "$user", public;
INSERT INTO "schema_migrations" (version) VALUES
+('20261009144947'),
('20261009130230'),
('20261009121104'),
('20261007082151'),
diff --git a/plugins/voice/README.md b/plugins/voice/README.md
index bc921bd3961..390df9728da 100644
--- a/plugins/voice/README.md
+++ b/plugins/voice/README.md
@@ -34,7 +34,8 @@ The plugin seeds a default "Watercooler" room on first enable.
| `voice_create_room_allowed_groups` | Groups that can create new rooms (default: admins, moderators, TL2). |
| `voice_max_rooms_per_user` | Max rooms per creator (default 5). |
| `voice_participant_ttl_seconds` | Redis presence TTL in seconds (default 30). Client heartbeat refreshes every 10s. |
-| `voice_video_enabled` | Allow camera video and screen sharing (default off). Rooms can opt out individually. |
+| `voice_video_allowed_groups` | Groups that can share their camera. Empty turns cameras off site-wide. |
+| `voice_screen_share_allowed_groups` | Groups that can share their screen. Empty turns screen sharing off site-wide. |
| `voice_video_max_publishers` | Max simultaneous video/screen publishers per room (default 8). |
| `voice_video_background_blur_enabled` | Allow users to blur their camera background (default on; requires video). |
| `voice_stun_servers` | STUN server addresses (pipe-separated). |
@@ -45,7 +46,7 @@ The plugin seeds a default "Watercooler" room on first enable.
## Video
-When `voice_video_enabled` is on (and the room's own video toggle is too), the room view at `/voice/r/<slug>` shows a video grid alongside the usual controls. Audio joins stay sidebar-first and unchanged; video lives on the page.
+When a user's groups allow camera or screen sharing (and the room's own video toggle is on), the room view at `/voice/r/<slug>` shows a video grid alongside the usual controls. Audio joins stay sidebar-first and unchanged; video lives on the page.
- Still pure mesh: a video m-line is pre-negotiated on every peer connection, so toggling the camera or a screen share is a `replaceTrack` with no renegotiation.
- Senders attach video only toward participants currently on the room page (`watching_video` presence flag) — every skipped peer saves a full encoder session.
diff --git a/plugins/voice/app/controllers/voice/rooms_controller.rb b/plugins/voice/app/controllers/voice/rooms_controller.rb
index 437b95232cc..56b72de93b5 100644
--- a/plugins/voice/app/controllers/voice/rooms_controller.rb
+++ b/plugins/voice/app/controllers/voice/rooms_controller.rb
@@ -428,17 +428,14 @@ module Voice
def participants
guardian.ensure_can_join_voice_room!(@room)
- all_metadata = Voice::ParticipantTracker.get_all_metadata(@room.id)
render json: {
participants:
- Voice::ParticipantTracker
- .list(@room.id)
- .map do |user|
- BasicUserSerializer
- .new(user, scope: guardian, root: false)
- .as_json
- .merge(all_metadata[user.id] || {})
- end,
+ Voice::RoomBroadcaster.participant_entries(
+ @room,
+ Voice::ParticipantTracker.list(@room.id),
+ guardian: guardian,
+ metadata: Voice::ParticipantTracker.get_all_metadata(@room.id),
+ ),
}
end
@@ -461,11 +458,15 @@ module Voice
wants_camera = params.key?(:video) && bool.cast(params[:video])
wants_screen = params.key?(:screen) && bool.cast(params[:screen])
- if wants_camera || wants_screen
- unless @room.video_allowed? && guardian.can_speak_in_voice_room?(@room)
- raise Discourse::InvalidAccess.new(I18n.t("voice.errors.video_not_allowed"))
- end
+ if wants_camera && !guardian.can_publish_video_in_voice_room?(@room)
+ raise Discourse::InvalidAccess.new(I18n.t("voice.errors.video_not_allowed"))
+ end
+ if wants_screen && !guardian.can_screen_share_in_voice_room?(@room)
+ raise Discourse::InvalidAccess.new(I18n.t("voice.errors.screen_share_not_allowed"))
+ end
+
+ if wants_camera || wants_screen
if video_publisher_count(@room, exclude_user_id: current_user.id) >=
SiteSetting.voice_video_max_publishers
raise Discourse::InvalidParameters.new(I18n.t("voice.errors.video_publisher_limit"))
diff --git a/plugins/voice/app/models/voice/room.rb b/plugins/voice/app/models/voice/room.rb
index 50f679a2ac9..9102e15eb4e 100644
--- a/plugins/voice/app/models/voice/room.rb
+++ b/plugins/voice/app/models/voice/room.rb
@@ -96,12 +96,6 @@ module Voice
[max_participants, SiteSetting.voice_max_room_participants].compact.min
end
- # Room-level capability only; per-user publish rights are guardian-driven
- # (stage listeners never publish even when this is true).
- def video_allowed?
- SiteSetting.voice_video_enabled && video_enabled
- end
-
def membership_for(user)
return if user.blank?
diff --git a/plugins/voice/app/serializers/voice/room_serializer.rb b/plugins/voice/app/serializers/voice/room_serializer.rb
index 0ad1deda2cd..776a8f666aa 100644
--- a/plugins/voice/app/serializers/voice/room_serializer.rb
+++ b/plugins/voice/app/serializers/voice/room_serializer.rb
@@ -23,6 +23,7 @@ module Voice
:visit_count,
:video_enabled,
:video_allowed,
+ :screen_share_allowed,
:chat_channel_id,
:chat_idle_minutes,
:chat_available,
@@ -73,12 +74,12 @@ module Voice
end
def active_participants
- tracked_participants.map do |user|
- BasicUserSerializer
- .new(user, scope: scope, root: false)
- .as_json
- .merge(participant_metadata[user.id] || {})
- end
+ Voice::RoomBroadcaster.participant_entries(
+ object,
+ tracked_participants,
+ guardian: scope,
+ metadata: participant_metadata,
+ )
end
def room_type
@@ -110,8 +111,24 @@ module Voice
scope.user.present? && @options[:include_visit_count]
end
+ # Per-user publish rights, so they are omitted from the anonymously-scoped
+ # directory broadcasts (the client keeps the ones it already knows). The
+ # room's own video_enabled and the stage role are left out: broadcasts
+ # carry both live and the client combines them with these.
def video_allowed
- object.video_allowed?
+ scope.eligible_to_publish_video_in_voice_room?(object)
+ end
+
+ def include_video_allowed?
+ scope.user.present?
+ end
+
+ def screen_share_allowed
+ scope.eligible_to_screen_share_in_voice_room?(object)
+ end
+
+ def include_screen_share_allowed?
+ scope.user.present?
end
def chat_available
diff --git a/plugins/voice/app/services/voice/room_broadcaster.rb b/plugins/voice/app/services/voice/room_broadcaster.rb
index 3a1cc99e9da..0ae96eaaf40 100644
--- a/plugins/voice/app/services/voice/room_broadcaster.rb
+++ b/plugins/voice/app/services/voice/room_broadcaster.rb
@@ -32,25 +32,37 @@ module Voice
)
end
+ # Each entry carries the sender's own publish entitlements: mesh peers
+ # exchange media directly, so a receiver decides whether to play a video
+ # or screen-audio track from this, not from its own rights. Every roster
+ # a client can seed from goes through here so none of them lacks them.
+ def self.participant_entries(room, users, guardian:, metadata:)
+ entitlements = Voice::MediaEntitlements.for_users(room, users)
+
+ users.map do |user|
+ BasicUserSerializer
+ .new(user, scope: guardian, root: false)
+ .as_json
+ .merge(metadata[user.id] || {})
+ .merge(entitlements[user.id] || Voice::MediaEntitlements::NONE)
+ end
+ end
+
def initialize(room)
@room = room
end
def publish_participants(fingerprint: nil)
- guardian = Guardian.new(nil)
- all_metadata = Voice::ParticipantTracker.get_all_metadata(room.id)
payload = {
type: "participants",
room_id: room.id,
participants:
- Voice::ParticipantTracker
- .list(room.id)
- .map do |user|
- BasicUserSerializer
- .new(user, scope: guardian, root: false)
- .as_json
- .merge(all_metadata[user.id] || {})
- end,
+ self.class.participant_entries(
+ room,
+ Voice::ParticipantTracker.list(room.id),
+ guardian: Guardian.new(nil),
+ metadata: Voice::ParticipantTracker.get_all_metadata(room.id),
+ ),
}
MessageBus.publish(Voice.room_channel(room.id), payload, **room_message_bus_targets)
diff --git a/plugins/voice/assets/javascripts/discourse/app/services/voice-rooms.js b/plugins/voice/assets/javascripts/discourse/app/services/voice-rooms.js
index 0e2efcbee6a..7cb53bcb73c 100644
--- a/plugins/voice/assets/javascripts/discourse/app/services/voice-rooms.js
+++ b/plugins/voice/assets/javascripts/discourse/app/services/voice-rooms.js
@@ -13,6 +13,8 @@ const USER_GATED_ROOM_FIELDS = [
"chat_channel_id",
"chat_idle_minutes",
"livekit_enabled",
+ "video_allowed",
+ "screen_share_allowed",
];
// Participant broadcasts arrive in arbitrary database order, so every list
diff --git a/plugins/voice/assets/javascripts/discourse/app/services/voice-webrtc.js b/plugins/voice/assets/javascripts/discourse/app/services/voice-webrtc.js
index 7108de0b7a4..04644e49634 100644
--- a/plugins/voice/assets/javascripts/discourse/app/services/voice-webrtc.js
+++ b/plugins/voice/assets/javascripts/discourse/app/services/voice-webrtc.js
@@ -282,7 +282,7 @@ export default class VoiceWebrtcService extends Service {
getFirstActiveRoomId: () => this.#firstActiveRoomId(),
getActiveRoomId: () => this.activeRoomId,
getRoom: (roomId) => this.voiceRooms?.roomById(roomId),
- canPublishVideo: (roomId) => this.canPublishVideo(roomId),
+ canPublish: (kind, roomId) => this.canPublish(kind, roomId),
getCameraQuality: (roomId) => this.effectiveCameraQuality(roomId),
getScreenQuality: (roomId) => this.effectiveScreenQuality(roomId),
getScreenContent: () => this.screenContent,
@@ -393,6 +393,8 @@ export default class VoiceWebrtcService extends Service {
this.#remoteStreamRegistry.userIdsFor(roomId),
removeRemoteStream: (roomId, userId) =>
this.#removeRemoteStream(roomId, userId),
+ removeRemoteMedia: (roomId, userId, options) =>
+ this.#remoteStreamRegistry.removeMedia(roomId, userId, options),
removeAllRemoteStreams: (roomId) => this.#removeAllRemoteStreams(roomId),
getLocalVideoKind: () => this.localVideoKind,
syncVideoSenders: (roomId) => this.#localVideo.syncSenders(roomId),
@@ -1171,11 +1173,11 @@ export default class VoiceWebrtcService extends Service {
}
videoAllowedIn(room) {
- return !!(
- this.siteSettings.voice_video_enabled &&
- room?.video_enabled &&
- (room?.room_type !== "stage" || this.#canSpeakInRoom(room))
- );
+ return this.#mediaAllowedIn(room, room?.video_allowed);
+ }
+
+ screenShareAllowedIn(room) {
+ return this.#mediaAllowedIn(room, room?.screen_share_allowed);
}
videoPublisherCount(roomId) {
@@ -1186,23 +1188,22 @@ export default class VoiceWebrtcService extends Service {
).length;
}
- canPublishVideo(roomId) {
- const room = this.voiceRooms?.roomById(roomId);
- if (!room || !this.videoAllowedIn(room)) {
- return false;
- }
- if (!this.#activeRoomIds.has(roomId)) {
- return false;
- }
- if (this.localVideoKind) {
- return true;
- }
- return (
- this.videoPublisherCount(roomId) <
- this.siteSettings.voice_video_max_publishers
+ canPublishCamera(roomId) {
+ return this.#canPublishIn(roomId, (room) => this.videoAllowedIn(room));
+ }
+
+ canPublishScreen(roomId) {
+ return this.#canPublishIn(roomId, (room) =>
+ this.screenShareAllowedIn(room)
);
}
+ canPublish(kind, roomId) {
+ return kind === "screen"
+ ? this.canPublishScreen(roomId)
+ : this.canPublishCamera(roomId);
+ }
+
async toggleCamera() {
const userId = this.currentUser?.id;
if (!this.localVideoKind && this.#cameraRestorePromise) {
@@ -1413,6 +1414,35 @@ export default class VoiceWebrtcService extends Service {
return participantCanSpeak(room, this.currentUser?.id);
}
+ // The server-computed right, re-checked against the two things a broadcast
+ // can change under a live call: the room's own media flag (a per-user right
+ // is absent from anonymously-scoped broadcasts, so it survives them stale)
+ // and the caller's stage role.
+ #mediaAllowedIn(room, allowed) {
+ return !!(
+ allowed &&
+ room?.video_enabled &&
+ (room?.room_type !== "stage" || this.#canSpeakInRoom(room))
+ );
+ }
+
+ #canPublishIn(roomId, allowedIn) {
+ const room = this.voiceRooms?.roomById(roomId);
+ if (!room || !allowedIn(room)) {
+ return false;
+ }
+ if (!this.#activeRoomIds.has(roomId)) {
+ return false;
+ }
+ if (this.localVideoKind) {
+ return true;
+ }
+ return (
+ this.videoPublisherCount(roomId) <
+ this.siteSettings.voice_video_max_publishers
+ );
+ }
+
#isMeshRoom(roomId) {
return (this.#roomTransports.get(roomId) ?? "mesh") === "mesh";
}
@@ -1460,7 +1490,7 @@ export default class VoiceWebrtcService extends Service {
this.watchingRoomId !== roomId ||
this.localVideoKind ||
!this.#cameraPreferred(userId) ||
- !this.canPublishVideo(roomId)
+ !this.canPublishCamera(roomId)
) {
return;
}
@@ -1474,7 +1504,7 @@ export default class VoiceWebrtcService extends Service {
this.watchingRoomId === roomId &&
(!this.localVideoKind || this.localVideoKind === "camera") &&
this.#cameraPreferred(userId) &&
- this.canPublishVideo(roomId),
+ this.canPublishCamera(roomId),
})
.catch(() => {
voiceLog.warn("[voice] failed to restore preferred camera state");
@@ -1565,7 +1595,12 @@ export default class VoiceWebrtcService extends Service {
}
const room = this.voiceRooms?.roomById(roomId);
- if (room && !this.videoAllowedIn(room)) {
+ const stillAllowed =
+ this.localVideoKind === "screen"
+ ? this.screenShareAllowedIn(room)
+ : this.videoAllowedIn(room);
+
+ if (room && !stillAllowed) {
this.#localVideo.stop().catch(() => {});
this.toasts.default({
duration: 5000,
@@ -1750,18 +1785,25 @@ export default class VoiceWebrtcService extends Service {
}
// Mesh receive-side media boundary: only register (and therefore play) a
- // remote track the sender's server-attested role and the room's media
- // policy allow. On LiveKit the SFU enforces publish permissions instead.
+ // remote track the sender's server-attested role, entitlements and the
+ // room's media policy allow. On LiveKit the SFU enforces publish
+ // permissions instead.
#registerRemoteTrack(roomId, userId, track, streams) {
const room = this.voiceRooms?.roomById(roomId);
- if (!remoteTrackAllowed(room, userId, track, streams)) {
+ const mesh = this.#isMeshRoom(roomId);
+ if (!remoteTrackAllowed(room, userId, track, streams, { mesh })) {
voiceLog.warn(
`[voice] dropping ${track?.kind} track from peer: not allowed to publish in room ${roomId}`
);
- try {
- track?.stop();
- } catch {
- // a remote track may already be ended
+ // A pre-negotiated video or screen-audio receiver keeps one track for
+ // the connection's lifetime, so stopping it would leave the sender dark
+ // even once allowed. Left unregistered, it is never played.
+ if (track?.kind === "audio" && streams?.length) {
+ try {
+ track.stop();
+ } catch {
+ // a remote track may already be ended
+ }
}
return;
}
diff --git a/plugins/voice/assets/javascripts/discourse/components/voice-room-form.gjs b/plugins/voice/assets/javascripts/discourse/components/voice-room-form.gjs
index eae4a6ad86e..5fd7d57c275 100644
--- a/plugins/voice/assets/javascripts/discourse/components/voice-room-form.gjs
+++ b/plugins/voice/assets/javascripts/discourse/components/voice-room-form.gjs
@@ -39,7 +39,7 @@ export default class VoiceRoomForm extends Component {
}
get showVideoToggle() {
- return this.siteSettings.voice_video_enabled;
+ return this.site.voice_video_available;
}
get showLivekitToggle() {
diff --git a/plugins/voice/assets/javascripts/discourse/components/voice/call-controls.gjs b/plugins/voice/assets/javascripts/discourse/components/voice/call-controls.gjs
index 20dd3c806f5..57a94658a76 100644
--- a/plugins/voice/assets/javascripts/discourse/components/voice/call-controls.gjs
+++ b/plugins/voice/assets/javascripts/discourse/components/voice/call-controls.gjs
@@ -63,6 +63,10 @@ export default class VoiceCallControls extends Component {
return this.voiceWebrtc.videoAllowedIn(this.room);
}
+ get screenShareAllowed() {
+ return this.voiceWebrtc.screenShareAllowedIn(this.room);
+ }
+
get cameraActive() {
return this.voiceWebrtc.localVideoKind === "camera";
}
@@ -73,19 +77,19 @@ export default class VoiceCallControls extends Component {
get cameraDisabled() {
return (
- !this.cameraActive && !this.voiceWebrtc.canPublishVideo(this.room?.id)
+ !this.cameraActive && !this.voiceWebrtc.canPublishCamera(this.room?.id)
);
}
get screenShareDisabled() {
return (
!this.screenShareActive &&
- !this.voiceWebrtc.canPublishVideo(this.room?.id)
+ !this.voiceWebrtc.canPublishScreen(this.room?.id)
);
}
get showScreenShare() {
- return this.videoAllowed && this.voiceWebrtc.screenShareSupported;
+ return this.screenShareAllowed && this.voiceWebrtc.screenShareSupported;
}
get #ownParticipant() {
diff --git a/plugins/voice/assets/javascripts/discourse/lib/voice/local-video-manager.js b/plugins/voice/assets/javascripts/discourse/lib/voice/local-video-manager.js
index 2c29a51b13f..6a565ec3b0e 100644
--- a/plugins/voice/assets/javascripts/discourse/lib/voice/local-video-manager.js
+++ b/plugins/voice/assets/javascripts/discourse/lib/voice/local-video-manager.js
@@ -46,7 +46,7 @@ export default class LocalVideoManager {
#getFirstActiveRoomId;
#getActiveRoomId;
#getRoom;
- #canPublishVideo;
+ #canPublish;
#getCameraQuality;
#getScreenQuality;
#getScreenContent;
@@ -66,7 +66,7 @@ export default class LocalVideoManager {
this.#getFirstActiveRoomId = options.getFirstActiveRoomId;
this.#getActiveRoomId = options.getActiveRoomId;
this.#getRoom = options.getRoom;
- this.#canPublishVideo = options.canPublishVideo;
+ this.#canPublish = options.canPublish;
this.#getCameraQuality = options.getCameraQuality;
this.#getScreenQuality = options.getScreenQuality;
this.#getScreenContent = options.getScreenContent;
@@ -162,7 +162,7 @@ export default class LocalVideoManager {
return;
}
- if (!this.#canPublishVideo(roomId)) {
+ if (!this.#canPublish(kind, roomId)) {
if (!silent) {
this.#showError("voice.video.publisher_limit");
}
diff --git a/plugins/voice/assets/javascripts/discourse/lib/voice/peer-manager.js b/plugins/voice/assets/javascripts/discourse/lib/voice/peer-manager.js
index 83102b36f38..8102c68398e 100644
--- a/plugins/voice/assets/javascripts/discourse/lib/voice/peer-manager.js
+++ b/plugins/voice/assets/javascripts/discourse/lib/voice/peer-manager.js
@@ -228,6 +228,15 @@ export default class PeerManager {
return PeerManager.videoTransceiverFor(pc)?.receiver?.track || null;
}
+ remoteScreenAudioTrack(roomId, userId) {
+ const pc = this.get(roomId, userId);
+ if (!pc) {
+ return null;
+ }
+
+ return PeerManager.screenAudioTransceiverFor(pc)?.receiver?.track || null;
+ }
+
allPeerConnections() {
return this.#peerConnections;
}
diff --git a/plugins/voice/assets/javascripts/discourse/lib/voice/remote-stream-registry.js b/plugins/voice/assets/javascripts/discourse/lib/voice/remote-stream-registry.js
index 54db9702f6e..0c0ce872f9e 100644
--- a/plugins/voice/assets/javascripts/discourse/lib/voice/remote-stream-registry.js
+++ b/plugins/voice/assets/javascripts/discourse/lib/voice/remote-stream-registry.js
@@ -110,6 +110,35 @@ export default class RemoteStreamRegistry {
}
}
+ // Revokes a sender's video and screen audio while leaving their microphone
+ // playing — what a lost publish entitlement costs them. `keepVideo` revokes
+ // screen audio alone, for a sender who may still use the camera.
+ removeMedia(roomId, userId, { keepVideo = false } = {}) {
+ const entry = (this.#streams.get(roomId) || []).find(
+ (candidate) => Number(candidate?.userId) === Number(userId)
+ );
+
+ if (!entry) {
+ return false;
+ }
+
+ const videoTracks = keepVideo ? [] : entry.stream.getVideoTracks();
+ const screenAudioTracks = entry.screenAudioStream?.getTracks() || [];
+
+ if (!videoTracks.length && !screenAudioTracks.length) {
+ return false;
+ }
+
+ videoTracks.forEach((track) => entry.stream.removeTrack(track));
+ screenAudioTracks.forEach((track) =>
+ entry.screenAudioStream.removeTrack(track)
+ );
+ entry.screenAudioStream = null;
+
+ this.#onChange();
+ return true;
+ }
+
remove(roomId, userId) {
if (!roomId || !userId) {
return false;
diff --git a/plugins/voice/assets/javascripts/discourse/lib/voice/roster-handler.js b/plugins/voice/assets/javascripts/discourse/lib/voice/roster-handler.js
index 3b2469b38cd..9e20106b751 100644
--- a/plugins/voice/assets/javascripts/discourse/lib/voice/roster-handler.js
+++ b/plugins/voice/assets/javascripts/discourse/lib/voice/roster-handler.js
@@ -5,7 +5,7 @@ import {
playUserLeftSound,
stopCallSounds,
} from "./sound-effects";
-import { participantCanSpeak } from "./stage-roles";
+import { participantCanSpeak, participantEntitledToMedia } from "./stage-roles";
// Handles the roster-shaped room messages ("participants", "role_change",
// "hand_raise"): diffing the roster into mesh peer create/destroy (or the
@@ -28,6 +28,7 @@ export default class RosterHandler {
#registerTrack;
#getRemoteUserIds;
#removeRemoteStream;
+ #removeRemoteMedia;
#removeAllRemoteStreams;
#getLocalVideoKind;
#syncVideoSenders;
@@ -53,6 +54,7 @@ export default class RosterHandler {
registerTrack,
getRemoteUserIds = () => [],
removeRemoteStream,
+ removeRemoteMedia = () => {},
removeAllRemoteStreams,
getLocalVideoKind,
syncVideoSenders,
@@ -77,6 +79,7 @@ export default class RosterHandler {
this.#registerTrack = registerTrack;
this.#getRemoteUserIds = getRemoteUserIds;
this.#removeRemoteStream = removeRemoteStream;
+ this.#removeRemoteMedia = removeRemoteMedia;
this.#removeAllRemoteStreams = removeAllRemoteStreams;
this.#getLocalVideoKind = getLocalVideoKind;
this.#syncVideoSenders = syncVideoSenders;
@@ -182,8 +185,9 @@ export default class RosterHandler {
}
}
- this.#syncRemoteVideoTracks(roomId, participants);
+ this.#syncRemoteMediaTracks(roomId, participants);
this.#dropDisallowedStreams(roomId, participants, { isStage });
+ this.#dropUnentitledMedia(roomId, participants);
if (!this.#isMeshRoom(roomId)) {
// Publisher-count changes move camera subscriptions between simulcast
@@ -237,7 +241,7 @@ export default class RosterHandler {
}
}
- #syncRemoteVideoTracks(roomId, participants) {
+ #syncRemoteMediaTracks(roomId, participants) {
for (const participant of participants || []) {
const participantId = Number(participant?.id);
if (!participantId || participantId === this.#getCurrentUserId()) {
@@ -252,6 +256,18 @@ export default class RosterHandler {
if (track) {
this.#registerTrack(roomId, participantId, track);
}
+
+ // Screen audio dropped by a revoked entitlement never gets another
+ // ontrack once the right comes back.
+ if (participant.is_screen_sharing) {
+ const screenAudioTrack = this.#peerManager.remoteScreenAudioTrack(
+ roomId,
+ participantId
+ );
+ if (screenAudioTrack) {
+ this.#registerTrack(roomId, participantId, screenAudioTrack);
+ }
+ }
}
}
@@ -281,6 +297,34 @@ export default class RosterHandler {
}
}
+ // The receive-side policy refuses new tracks; this drops the camera or
+ // screen media of a mesh sender whose entitlement was revoked while it
+ // played. Only a lost entitlement counts — a sender who merely stopped
+ // publishing keeps its idle tracks for the next time it starts.
+ #dropUnentitledMedia(roomId, participants) {
+ if (!this.#isMeshRoom(roomId)) {
+ return;
+ }
+
+ for (const participant of participants || []) {
+ const participantId = Number(participant?.id);
+ if (!participantId || participantId === this.#getCurrentUserId()) {
+ continue;
+ }
+
+ if (!participantEntitledToMedia(participant)) {
+ this.#removeRemoteMedia(roomId, participantId);
+ } else if (
+ !participantEntitledToMedia(participant, { screenOnly: true })
+ ) {
+ // While sharing, the one video m-line is carrying the screen.
+ this.#removeRemoteMedia(roomId, participantId, {
+ keepVideo: !participant.is_screen_sharing,
+ });
+ }
+ }
+ }
+
async #handleOwnRoleChange(roomId, newRole) {
const canSpeak = newRole === "speaker" || newRole === "moderator";
diff --git a/plugins/voice/assets/javascripts/discourse/lib/voice/stage-roles.js b/plugins/voice/assets/javascripts/discourse/lib/voice/stage-roles.js
index 943f849c36b..c74d0f556e6 100644
--- a/plugins/voice/assets/javascripts/discourse/lib/voice/stage-roles.js
+++ b/plugins/voice/assets/javascripts/discourse/lib/voice/stage-roles.js
@@ -17,17 +17,66 @@ export function participantCanSpeak(room, userId) {
// authority, so a track is only registered and played when the sender's
// server-side role and the room's media policy allow publishing it.
//
+// On mesh rooms nothing else stands between a sender and its peers, so a
+// camera, screen, or screen-audio track additionally requires the sender's
+// own server-attested entitlement. Not its published state: the
+// pre-negotiated transceivers deliver their tracks when the connection is
+// set up, long before the sender turns anything on. LiveKit rooms skip this
+// check: the SFU refuses unauthorized track sources at publish time, and its
+// subscriptions can arrive ahead of the roster broadcast.
+//
// Mic audio arrives with the sender's stream attached; the pre-negotiated
// screen-audio transceiver delivers a bare track (see RemoteStreamRegistry).
-export function remoteTrackAllowed(room, userId, track, streams) {
+export function remoteTrackAllowed(
+ room,
+ userId,
+ track,
+ streams,
+ { mesh = false } = {}
+) {
if (!room || !track) {
return false;
}
const isScreenAudio = track.kind === "audio" && !streams?.length;
- if ((track.kind === "video" || isScreenAudio) && !room.video_allowed) {
- return false;
+ if (track.kind === "video" || isScreenAudio) {
+ if (!room.video_enabled) {
+ return false;
+ }
+
+ if (
+ mesh &&
+ !senderEntitledToMedia(room, userId, { screenOnly: isScreenAudio })
+ ) {
+ return false;
+ }
}
return participantCanSpeak(room, userId);
}
+
+// Mesh carries camera and screen on one video m-line, so the video track is
+// allowed for a sender entitled to either; screen audio needs screen sharing.
+export function participantEntitledToMedia(
+ participant,
+ { screenOnly = false } = {}
+) {
+ if (!participant) {
+ return false;
+ }
+
+ if (screenOnly) {
+ return !!participant.can_screen_share;
+ }
+
+ return !!(participant.can_publish_video || participant.can_screen_share);
+}
+
+function senderEntitledToMedia(room, userId, options) {
+ return participantEntitledToMedia(
+ (room.active_participants || []).find(
+ (p) => Number(p?.id) === Number(userId)
+ ),
+ options
+ );
+}
diff --git a/plugins/voice/config/locales/client.en.yml b/plugins/voice/config/locales/client.en.yml
index c5e4a7a3e69..898f0511273 100644
--- a/plugins/voice/config/locales/client.en.yml
+++ b/plugins/voice/config/locales/client.en.yml
@@ -391,8 +391,8 @@ en:
max_participants: "Max participants"
max_participants_help: "Maximum participants allowed (2-50, or 2-200 for Stage rooms)."
video_enabled: "Video"
- video_enabled_help: "Allow participants to share their camera and screen in this room."
- video_enabled_stage_help: "Allow speakers and moderators to share their camera and screen in this room. Listeners can only watch."
+ video_enabled_help: "Allow participants to share their camera and screen in this room, if the site settings allow their groups to."
+ video_enabled_stage_help: "Allow speakers and moderators to share their camera and screen in this room, if the site settings allow their groups to. Listeners can only watch."
livekit_enabled: "Use media server (SFU)"
livekit_enabled_help: "Route this room's calls through the site's LiveKit media server instead of the peer-to-peer mesh. A call already in progress is not affected — the room switches when its next call starts."
chat_channel: "Chat channel"
diff --git a/plugins/voice/config/locales/server.en.yml b/plugins/voice/config/locales/server.en.yml
index b200161b9b5..d3df172f6f5 100644
--- a/plugins/voice/config/locales/server.en.yml
+++ b/plugins/voice/config/locales/server.en.yml
@@ -18,7 +18,8 @@ en:
voice_idle_threshold_minutes: "Minutes of inactivity before a voice room participant is marked as idle. Set to 0 to disable."
voice_afk_auto_mute_threshold_minutes: "Minutes of inactivity before a voice room participant is automatically muted. Set to 0 to disable."
voice_afk_disconnect_threshold_minutes: "Minutes of inactivity before a voice room participant is automatically disconnected. Set to 0 to disable."
- voice_video_enabled: "Enable camera video and screen sharing in voice rooms. Rooms can individually opt out via their room settings."
+ voice_video_allowed_groups: "Groups whose members can share their camera in voice rooms. Leave empty to turn camera video off site-wide. Rooms can individually opt out of all media via their room settings, and stage room listeners can never publish."
+ voice_screen_share_allowed_groups: "Groups whose members can share their screen in voice rooms. Leave empty to turn screen sharing off site-wide. Rooms can individually opt out of all media via their room settings, and stage room listeners can never publish."
voice_video_max_publishers: "Maximum number of participants who can share video or their screen at the same time in a room. On peer-to-peer rooms, higher values increase CPU and bandwidth load for everyone watching; on rooms using a LiveKit media server, they mainly increase load on that server."
voice_video_background_blur_enabled: "Allow participants to blur their camera background. Segmentation runs on the publisher's device via MediaPipe, which increases CPU/GPU load while their camera is on."
voice_subtitles_enabled: "Allow participants to turn on live subtitles for other people's speech. Transcription runs entirely on the viewer's device via an NVIDIA Parakeet speech-to-text model (~2.5 GB, downloaded on first use, WebGPU required); no audio leaves the browser."
@@ -85,7 +86,8 @@ en:
cannot_kick_self: "You cannot kick yourself from the room."
cannot_kick_creator: "You cannot kick the room creator."
listeners_cannot_unmute: "Listeners cannot unmute in a Stage room."
- video_not_allowed: "Video is not enabled in this room."
+ video_not_allowed: "You are not allowed to share your camera in this room."
+ screen_share_not_allowed: "You are not allowed to share your screen in this room."
video_publisher_limit: "The maximum number of simultaneous video streams for this room has been reached."
chat_unavailable: "Chat is not available for this room."
chat_requires_presence: "Join the voice room to use its chat."
diff --git a/plugins/voice/config/locales/server.tr_TR.yml b/plugins/voice/config/locales/server.tr_TR.yml
index fe69a957aec..5d4fe8e6d14 100644
--- a/plugins/voice/config/locales/server.tr_TR.yml
+++ b/plugins/voice/config/locales/server.tr_TR.yml
@@ -14,7 +14,6 @@ tr_TR:
voice_idle_threshold_minutes: "Sesli oda katılımcısının boşta olarak işaretlenmesi için geçmesi gereken etkinlik dışı dakika sayısı. Kapatmak için 0 yapın."
voice_afk_auto_mute_threshold_minutes: "Sesli oda katılımcısının mikrofonunun otomatik kapatılması için geçmesi gereken etkinlik dışı dakika sayısı. Kapatmak için 0 yapın."
voice_afk_disconnect_threshold_minutes: "Sesli oda katılımcısının bağlantısının otomatik kesilmesi için geçmesi gereken etkinlik dışı dakika sayısı. Kapatmak için 0 yapın."
- voice_video_enabled: "Sesli odalarda kamera videosunu ve ekran paylaşımını etkinleştir. Her oda kendi ayarlarından bunları kapatabilir."
voice_video_max_publishers: "Bir odada aynı anda video veya ekran paylaşabilen en fazla katılımcı sayısı. Eşler arası odalarda yüksek değerler tüm izleyicilerin işlemci ve bant genişliği yükünü artırır; LiveKit medya sunucusu kullanan odalarda ise ağırlıklı olarak sunucu yükünü artırır."
voice_video_background_blur_enabled: "Katılımcıların kamera arka planını bulanıklaştırmasına izin ver. Bölümleme, yayıncının aygıtında MediaPipe ile çalışır ve kamera açıkken işlemci/GPU yükünü artırır."
voice_subtitles_enabled: "Katılımcıların diğer kişilerin konuşmaları için canlı altyazıları açmasına izin ver. Yazıya aktarma tamamen izleyicinin aygıtında NVIDIA Parakeet konuşmadan metne modeliyle çalışır (yaklaşık 2,5 GB, ilk kullanımda indirilir, WebGPU gerekir); ses tarayıcıdan dışarı çıkmaz."
diff --git a/plugins/voice/config/settings.yml b/plugins/voice/config/settings.yml
index 00027f22e97..8d9f77ffb29 100644
--- a/plugins/voice/config/settings.yml
+++ b/plugins/voice/config/settings.yml
@@ -127,9 +127,24 @@ plugins:
default: ""
regex: '^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$'
validator: "VoiceLivekitRecordingS3BucketValidator"
- voice_video_enabled:
- default: true
- client: true
+ voice_video_allowed_groups:
+ type: group_list
+ list_type: compact
+ default: "5" # auto group logged_in_users
+ allow_any: false
+ refresh: true
+ disallowed_groups: "0|4"
+ depends_on:
+ - voice_enabled
+ voice_screen_share_allowed_groups:
+ type: group_list
+ list_type: compact
+ default: "5" # auto group logged_in_users
+ allow_any: false
+ refresh: true
+ disallowed_groups: "0|4"
+ depends_on:
+ - voice_enabled
voice_video_max_publishers:
default: 8
min: 2
diff --git a/plugins/voice/db/post_migrate/20261009144947_replace_voice_video_enabled_setting.rb b/plugins/voice/db/post_migrate/20261009144947_replace_voice_video_enabled_setting.rb
new file mode 100644
index 00000000000..7a1c781310d
--- /dev/null
+++ b/plugins/voice/db/post_migrate/20261009144947_replace_voice_video_enabled_setting.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class ReplaceVoiceVideoEnabledSetting < ActiveRecord::Migration[8.0]
+ GROUP_LIST_DATA_TYPE = 20
+
+ # Camera and screen sharing moved from one site-wide boolean to a group list
+ # each, whose defaults grant both to logged-in users. A site that had turned
+ # video off has to keep it off, which an unset group list would not do.
+ def up
+ video_was_off =
+ DB.query_single("SELECT value FROM site_settings WHERE name = 'voice_video_enabled'").first ==
+ "f"
+
+ if video_was_off
+ %w[voice_video_allowed_groups voice_screen_share_allowed_groups].each do |name|
+ DB.exec(<<~SQL, name: name, data_type: GROUP_LIST_DATA_TYPE)
+ INSERT INTO site_settings (name, data_type, value, created_at, updated_at)
+ VALUES (:name, :data_type, '', NOW(), NOW())
+ ON CONFLICT (name) DO NOTHING
+ SQL
+ end
+ end
+
+ execute "DELETE FROM site_settings WHERE name = 'voice_video_enabled'"
+ end
+
+ def down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
diff --git a/plugins/voice/docs/ARCHITECTURE.md b/plugins/voice/docs/ARCHITECTURE.md
index e543b7c0e6d..8cfa734b520 100644
--- a/plugins/voice/docs/ARCHITECTURE.md
+++ b/plugins/voice/docs/ARCHITECTURE.md
@@ -19,6 +19,7 @@ Voice adds lightweight WebRTC voice rooms to Discourse without proxying audio/vi
- `RoomMembershipsController` lets moderators manage explicit memberships.
- **Authorization**
- Guardian extensions gate room visibility, membership, and management. Site settings define who can create/manage rooms and cap per-user ownership tallies.
+ - Camera and screen sharing are separate group-gated capabilities, resolved per user against the room's own media flag and their speaking rights. Publishing is enforced at the state endpoint and, on LiveKit rooms, by the token's track-source grants. Each room's serialization carries the viewer's own two rights for the UI, and every roster entry carries that sender's entitlements — mesh peers exchange media directly, so receivers gate video and screen audio on the sender's server-attested entitlement plus their published state.
## Frontend
diff --git a/plugins/voice/lib/voice.rb b/plugins/voice/lib/voice.rb
index bddc032b93a..aa7867bf1da 100644
--- a/plugins/voice/lib/voice.rb
+++ b/plugins/voice/lib/voice.rb
@@ -57,6 +57,7 @@ require_relative "voice/livekit/room_service_client"
require_relative "voice/livekit/agent_dispatch_client"
require_relative "voice/livekit/cloud_agent_client"
require_relative "voice/livekit/webhook_verifier"
+require_relative "voice/media_entitlements"
require_relative "voice/room_hashtag_data_source"
require_relative "voice/user_status_manager"
require_relative "../app/services/voice/agent_manager"
diff --git a/plugins/voice/lib/voice/guardian_extension.rb b/plugins/voice/lib/voice/guardian_extension.rb
index d96f115d5f1..5a4edacfad7 100644
--- a/plugins/voice/lib/voice/guardian_extension.rb
+++ b/plugins/voice/lib/voice/guardian_extension.rb
@@ -144,6 +144,29 @@ module Voice
membership&.can_speak? || false
end
+ # Camera and screen sharing are gated independently, per user: the room
+ # must allow media at all, the user must be able to speak in it (a stage
+ # listener publishes nothing), and their groups must carry the capability.
+ def can_publish_video_in_voice_room?(room)
+ eligible_to_publish_video_in_voice_room?(room) && voice_room_media_live?(room)
+ end
+
+ def can_screen_share_in_voice_room?(room)
+ eligible_to_screen_share_in_voice_room?(room) && voice_room_media_live?(room)
+ end
+
+ # The same capability minus the room's media flag and the stage role,
+ # which clients track live from room and role_change broadcasts. This is
+ # the half that gets serialized, so neither re-enabling a room's media nor
+ # a promotion needs the room re-serialized for each user.
+ def eligible_to_publish_video_in_voice_room?(room)
+ voice_media_entitlements(room)[:can_publish_video]
+ end
+
+ def eligible_to_screen_share_in_voice_room?(room)
+ voice_media_entitlements(room)[:can_screen_share]
+ end
+
# Only stage-room listeners have anything to request — anyone who can
# already speak (including admins and everyone in open rooms) cannot.
def can_request_to_speak_in_voice_room?(room)
@@ -156,5 +179,17 @@ module Voice
raise Discourse::InvalidAccess.new(I18n.t("voice.errors.not_authorized"))
end
end
+
+ private
+
+ def voice_media_entitlements(room)
+ return Voice::MediaEntitlements::NONE unless can_join_voice_room?(room)
+
+ Voice::MediaEntitlements.for_user(user)
+ end
+
+ def voice_room_media_live?(room)
+ room.video_enabled? && can_speak_in_voice_room?(room)
+ end
end
end
diff --git a/plugins/voice/lib/voice/livekit.rb b/plugins/voice/lib/voice/livekit.rb
index 4a873959329..4c9d7736fff 100644
--- a/plugins/voice/lib/voice/livekit.rb
+++ b/plugins/voice/lib/voice/livekit.rb
@@ -67,14 +67,19 @@ module Voice
raw.present? ? Time.at(raw.to_f) : nil
end
- # The track sources a publisher may send, matching the room's
- # capabilities. Lowercase is the access-token grant spelling; RoomService
- # permission updates use the same names uppercased (the proto enum).
- def self.publish_sources(room, can_publish)
+ # The track sources a publisher may send. Camera and screen sharing are
+ # granted independently, so a user allowed only one of them gets a token
+ # the SFU will refuse the other on. Lowercase is the access-token grant
+ # spelling; RoomService permission updates use the same names uppercased
+ # (the proto enum).
+ def self.publish_sources(room, can_publish, guardian)
return [] unless can_publish
sources = ["microphone"]
- sources.concat(%w[camera screen_share screen_share_audio]) if room.video_allowed?
+ sources << "camera" if guardian.can_publish_video_in_voice_room?(room)
+ if guardian.can_screen_share_in_voice_room?(room)
+ sources.concat(%w[screen_share screen_share_audio])
+ end
sources
end
@@ -82,7 +87,7 @@ module Voice
raise MintError, "LiveKit is not fully configured" unless configured?
can_publish = guardian.can_speak_in_voice_room?(room)
- sources = publish_sources(room, can_publish)
+ sources = publish_sources(room, can_publish, guardian)
payload = {
iss: SiteSetting.voice_livekit_api_key,
diff --git a/plugins/voice/lib/voice/livekit/egress_client.rb b/plugins/voice/lib/voice/livekit/egress_client.rb
index 9bf40557301..c8b459785ac 100644
--- a/plugins/voice/lib/voice/livekit/egress_client.rb
+++ b/plugins/voice/lib/voice/livekit/egress_client.rb
@@ -41,7 +41,7 @@ module Voice
request(
"StartRoomCompositeEgress",
roomName: Livekit.room_name(room),
- audioOnly: !room.video_allowed?,
+ audioOnly: !room.video_enabled?,
fileOutputs: [output],
)
end
diff --git a/plugins/voice/lib/voice/livekit/room_service_client.rb b/plugins/voice/lib/voice/livekit/room_service_client.rb
index fa54b78e41f..00e424f79a9 100644
--- a/plugins/voice/lib/voice/livekit/room_service_client.rb
+++ b/plugins/voice/lib/voice/livekit/room_service_client.rb
@@ -27,8 +27,9 @@ module Voice
# grants — sending only `canPublish` would silently revoke
# `canSubscribe` and deafen the participant.
def update_participant(room, user, identity: nil)
+ guardian = user.guardian
can_publish =
- user.bot? ? user.id == AgentBot.user&.id : user.guardian.can_speak_in_voice_room?(room)
+ user.bot? ? user.id == AgentBot.user&.id : guardian.can_speak_in_voice_room?(room)
call(
room,
"UpdateParticipant",
@@ -39,7 +40,8 @@ module Voice
canSubscribe: true,
canPublish: can_publish,
canPublishData: false,
- canPublishSources: Livekit.publish_sources(room, can_publish).map(&:upcase),
+ canPublishSources:
+ Livekit.publish_sources(room, can_publish, guardian).map(&:upcase),
hidden: false,
recorder: false,
},
diff --git a/plugins/voice/lib/voice/media_entitlements.rb b/plugins/voice/lib/voice/media_entitlements.rb
new file mode 100644
index 00000000000..8ad7a6a7a8d
--- /dev/null
+++ b/plugins/voice/lib/voice/media_entitlements.rb
@@ -0,0 +1,68 @@
+# frozen_string_literal: true
+
+module Voice
+ # Who may publish camera and screen media, answered for a whole roster at
+ # once. Mesh peers attach media straight to each other, so a receiver has to
+ # know every sender's entitlement — not just its own — before it plays a
+ # video or screen-audio track; the roster carries these alongside each
+ # participant.
+ #
+ # Deliberately excludes the stage role, which clients already follow live
+ # through role_change broadcasts, and which would otherwise make every
+ # promotion a stale-payload bug.
+ class MediaEntitlements
+ NONE = { can_publish_video: false, can_screen_share: false }.freeze
+
+ class << self
+ def for_users(room, users)
+ users = Array(users)
+ return {} if users.blank?
+ return users.to_h { |user| [user.id, NONE] } if !room || !room.video_enabled?
+
+ video_ids = user_ids_in_groups(users, SiteSetting.voice_video_allowed_groups_map)
+ screen_ids = user_ids_in_groups(users, SiteSetting.voice_screen_share_allowed_groups_map)
+
+ users.to_h do |user|
+ [
+ user.id,
+ {
+ can_publish_video: video_ids.include?(user.id),
+ can_screen_share: screen_ids.include?(user.id),
+ },
+ ]
+ end
+ end
+
+ # The viewer's own group rights, independent of any room's media flag:
+ # that flag reaches clients through anonymously-scoped broadcasts, which
+ # can't carry per-user fields, so clients combine the two themselves.
+ # Asked once per room on room-list renders; `in_any_groups?` memoizes the
+ # user's group ids across those calls.
+ def for_user(user)
+ return NONE if user.blank?
+
+ {
+ can_publish_video: user.in_any_groups?(SiteSetting.voice_video_allowed_groups_map),
+ can_screen_share: user.in_any_groups?(SiteSetting.voice_screen_share_allowed_groups_map),
+ }
+ end
+
+ private
+
+ # Only `everyone` and `logged_in_users` carry no group_users rows, so
+ # core's own predicate decides those two (it also owns how `everyone` is
+ # read); everything else, auto groups included, is one query.
+ def user_ids_in_groups(users, group_ids)
+ return Set.new if group_ids.blank?
+
+ pseudo_groups =
+ group_ids & [Group::AUTO_GROUPS[:everyone], Group::AUTO_GROUPS[:logged_in_users]]
+ if pseudo_groups.present? && users.first.in_any_groups?(pseudo_groups)
+ return users.map(&:id).to_set
+ end
+
+ GroupUser.where(group_id: group_ids, user_id: users.map(&:id)).pluck(:user_id).to_set
+ end
+ end
+ end
+end
diff --git a/plugins/voice/plugin.rb b/plugins/voice/plugin.rb
index 351ec2e2be1..0ce3b6103e5 100644
--- a/plugins/voice/plugin.rb
+++ b/plugins/voice/plugin.rb
@@ -158,6 +158,14 @@ after_initialize do
SiteSetting.voice_livekit_room_policy == "per_room" && Voice::Livekit.configured?
end
+ # Gates the room-form media checkbox: with neither capability granted to any
+ # group, a room-level media toggle would decide nothing. The per-user rights
+ # themselves ride on each room's serialization instead.
+ add_to_serializer(:site, :voice_video_available) do
+ SiteSetting.voice_video_allowed_groups.present? ||
+ SiteSetting.voice_screen_share_allowed_groups.present?
+ end
+
Voice::DefaultRoomSeeder.ensure! if SiteSetting.voice_enabled?
Voice::AgentBot.ensure! if SiteSetting.voice_enabled?
diff --git a/plugins/voice/spec/lib/voice/guardian_extension_spec.rb b/plugins/voice/spec/lib/voice/guardian_extension_spec.rb
index 43ca0041eb8..215b4f32c44 100644
--- a/plugins/voice/spec/lib/voice/guardian_extension_spec.rb
+++ b/plugins/voice/spec/lib/voice/guardian_extension_spec.rb
@@ -277,4 +277,75 @@ RSpec.describe Voice::GuardianExtension do
expect(anonymous_guardian.can_request_to_speak_in_voice_room?(public_room)).to eq(false)
end
end
+
+ describe "media publish permissions" do
+ it "grants both capabilities to a member of the allowed groups" do
+ expect(member.guardian.can_publish_video_in_voice_room?(public_room)).to eq(true)
+ expect(member.guardian.can_screen_share_in_voice_room?(public_room)).to eq(true)
+ end
+
+ it "gates each capability on its own group setting" do
+ SiteSetting.voice_video_allowed_groups = "#{Group::AUTO_GROUPS[:trust_level_4]}"
+
+ expect(member.guardian.can_publish_video_in_voice_room?(public_room)).to eq(false)
+ expect(member.guardian.can_screen_share_in_voice_room?(public_room)).to eq(true)
+
+ SiteSetting.voice_screen_share_allowed_groups = ""
+
+ expect(member.guardian.can_screen_share_in_voice_room?(public_room)).to eq(false)
+ end
+
+ it "is false for both when the room has media disabled" do
+ public_room.update!(video_enabled: false)
+
+ expect(member.guardian.can_publish_video_in_voice_room?(public_room)).to eq(false)
+ expect(member.guardian.can_screen_share_in_voice_room?(public_room)).to eq(false)
+ end
+
+ it "is false for a stage listener, who publishes nothing" do
+ private_room.update!(room_type: Voice::Room::ROOM_TYPE_STAGE)
+
+ expect(member.guardian.can_publish_video_in_voice_room?(private_room)).to eq(false)
+ expect(member.guardian.can_screen_share_in_voice_room?(private_room)).to eq(false)
+ expect(room_speaker.guardian.can_publish_video_in_voice_room?(private_room)).to eq(true)
+ expect(room_speaker.guardian.can_screen_share_in_voice_room?(private_room)).to eq(true)
+ end
+
+ # Clients apply the role themselves, so a promotion takes effect without
+ # the room being re-serialized for the promoted user.
+ it "keeps a stage listener eligible so a promotion needs no fresh payload" do
+ private_room.update!(room_type: Voice::Room::ROOM_TYPE_STAGE)
+
+ expect(member.guardian.eligible_to_publish_video_in_voice_room?(private_room)).to eq(true)
+ expect(member.guardian.eligible_to_screen_share_in_voice_room?(private_room)).to eq(true)
+ end
+
+ it "is not eligible when the group or access says no" do
+ SiteSetting.voice_video_allowed_groups = ""
+
+ expect(member.guardian.eligible_to_publish_video_in_voice_room?(private_room)).to eq(false)
+ expect(outsider.guardian.eligible_to_screen_share_in_voice_room?(private_room)).to eq(false)
+ end
+
+ # The room flag reaches clients through anonymous broadcasts that can't
+ # refresh a per-user field, so folding it in would strand a "no" after
+ # the room's media is turned back on.
+ it "stays eligible while the room's media is off, but cannot publish" do
+ private_room.update!(video_enabled: false)
+
+ expect(member.guardian.eligible_to_screen_share_in_voice_room?(private_room)).to eq(true)
+ expect(member.guardian.can_screen_share_in_voice_room?(private_room)).to eq(false)
+ expect(member.guardian.can_publish_video_in_voice_room?(private_room)).to eq(false)
+ end
+
+ it "is false for a user who cannot join the room" do
+ expect(outsider.guardian.can_publish_video_in_voice_room?(private_room)).to eq(false)
+ expect(outsider.guardian.can_screen_share_in_voice_room?(private_room)).to eq(false)
+ end
+
+ it "is false for anonymous visitors" do
+ expect(anonymous_guardian.can_publish_video_in_voice_room?(public_room)).to eq(false)
+ expect(anonymous_guardian.can_screen_share_in_voice_room?(public_room)).to eq(false)
+ end
+ end
end
diff --git a/plugins/voice/spec/lib/voice/livekit/egress_client_spec.rb b/plugins/voice/spec/lib/voice/livekit/egress_client_spec.rb
index 941189887db..b0d7a0be38f 100644
--- a/plugins/voice/spec/lib/voice/livekit/egress_client_spec.rb
+++ b/plugins/voice/spec/lib/voice/livekit/egress_client_spec.rb
@@ -139,7 +139,7 @@ RSpec.describe Voice::Livekit::EgressClient do
end
it "POSTs the room name and file output with a roomRecord-granted token" do
- SiteSetting.voice_video_enabled = false
+ room.update!(video_enabled: false)
stub = twirp_stub("StartRoomCompositeEgress").to_return(body: { egressId: "EG_1" }.to_json)
result = described_class.start_room_composite(room, filepath: "voice/test-abc123")
@@ -167,7 +167,6 @@ RSpec.describe Voice::Livekit::EgressClient do
end
it "requests a full composite for a room with video enabled" do
- SiteSetting.voice_video_enabled = true
room.update!(video_enabled: true)
twirp_stub("StartRoomCompositeEgress").to_return(body: "{}")
diff --git a/plugins/voice/spec/lib/voice/livekit/room_service_client_spec.rb b/plugins/voice/spec/lib/voice/livekit/room_service_client_spec.rb
index 12efb268f40..85e3401a347 100644
--- a/plugins/voice/spec/lib/voice/livekit/room_service_client_spec.rb
+++ b/plugins/voice/spec/lib/voice/livekit/room_service_client_spec.rb
@@ -75,8 +75,6 @@ RSpec.describe Voice::Livekit::RoomServiceClient do
end
describe ".update_participant" do
- before { SiteSetting.voice_video_enabled = true }
-
it "sends the full permission set for a speaker in a video room" do
room.update!(video_enabled: true)
stub = twirp_stub("UpdateParticipant")
diff --git a/plugins/voice/spec/lib/voice/livekit_spec.rb b/plugins/voice/spec/lib/voice/livekit_spec.rb
index 4c5e62291b9..10fa68c7521 100644
--- a/plugins/voice/spec/lib/voice/livekit_spec.rb
+++ b/plugins/voice/spec/lib/voice/livekit_spec.rb
@@ -97,7 +97,6 @@ RSpec.describe Voice::Livekit do
end
it "mints a least-privilege token for a speaker in a video room" do
- SiteSetting.voice_video_enabled = true
room.update!(video_enabled: true)
freeze_time
@@ -125,8 +124,27 @@ RSpec.describe Voice::Livekit do
)
end
+ it "grants only the camera source when screen sharing is not allowed" do
+ SiteSetting.voice_screen_share_allowed_groups = ""
+ room.update!(video_enabled: true)
+
+ payload = decoded_token
+
+ expect(payload["video"]["canPublishSources"]).to eq(%w[microphone camera])
+ end
+
+ it "grants only the screen sources when the camera is not allowed" do
+ SiteSetting.voice_video_allowed_groups = ""
+ room.update!(video_enabled: true)
+
+ payload = decoded_token
+
+ expect(payload["video"]["canPublishSources"]).to eq(
+ %w[microphone screen_share screen_share_audio],
+ )
+ end
+
it "grants only the microphone source when the room has no video" do
- SiteSetting.voice_video_enabled = true
room.update!(video_enabled: false)
payload = decoded_token
@@ -146,7 +164,6 @@ RSpec.describe Voice::Livekit do
end
it "grants all publish sources to a stage speaker when the room has video" do
- SiteSetting.voice_video_enabled = true
room.update!(room_type: Voice::Room::ROOM_TYPE_STAGE, video_enabled: true)
room.room_memberships.create!(user: user, role: Voice::RoomMembership::ROLE_SPEAKER)
@@ -159,7 +176,6 @@ RSpec.describe Voice::Livekit do
end
it "grants only the microphone to a stage speaker when the room has no video" do
- SiteSetting.voice_video_enabled = true
room.update!(room_type: Voice::Room::ROOM_TYPE_STAGE, video_enabled: false)
room.room_memberships.create!(user: user, role: Voice::RoomMembership::ROLE_SPEAKER)
diff --git a/plugins/voice/spec/lib/voice/media_entitlements_spec.rb b/plugins/voice/spec/lib/voice/media_entitlements_spec.rb
new file mode 100644
index 00000000000..707de515bb7
--- /dev/null
+++ b/plugins/voice/spec/lib/voice/media_entitlements_spec.rb
@@ -0,0 +1,84 @@
+# frozen_string_literal: true
+
+RSpec.describe Voice::MediaEntitlements do
+ fab!(:member) { Fabricate(:user, trust_level: TrustLevel[2]) }
+ fab!(:low_trust_user) { Fabricate(:user, trust_level: TrustLevel[0]) }
+ fab!(:room) { Fabricate(:voice_room, public: true) }
+
+ before { SiteSetting.voice_enabled = true }
+
+ it "answers each capability per user in one pass" do
+ SiteSetting.voice_video_allowed_groups = Group::AUTO_GROUPS[:trust_level_2]
+ SiteSetting.voice_screen_share_allowed_groups = Group::AUTO_GROUPS[:logged_in_users]
+
+ entitlements = described_class.for_users(room, [member, low_trust_user])
+
+ expect(entitlements[member.id]).to eq(can_publish_video: true, can_screen_share: true)
+ expect(entitlements[low_trust_user.id]).to eq(can_publish_video: false, can_screen_share: true)
+ end
+
+ it "denies everything when the room has media disabled" do
+ room.update!(video_enabled: false)
+
+ expect(described_class.for_users(room, [member])[member.id]).to eq(described_class::NONE)
+ end
+
+ it "denies everything when a capability has no groups" do
+ SiteSetting.voice_video_allowed_groups = ""
+ SiteSetting.voice_screen_share_allowed_groups = ""
+
+ expect(described_class.for_users(room, [member])[member.id]).to eq(described_class::NONE)
+ end
+
+ it "resolves a group list of real groups without the pseudogroup shortcut" do
+ group = Fabricate(:group)
+ group.add(member)
+ SiteSetting.voice_video_allowed_groups = group.id.to_s
+ SiteSetting.voice_screen_share_allowed_groups = group.id.to_s
+
+ entitlements = described_class.for_users(room, [member, low_trust_user])
+
+ expect(entitlements[member.id]).to eq(can_publish_video: true, can_screen_share: true)
+ expect(entitlements[low_trust_user.id]).to eq(described_class::NONE)
+ end
+
+ describe ".for_user" do
+ it "matches the roster answer for a single user" do
+ SiteSetting.voice_video_allowed_groups = Group::AUTO_GROUPS[:trust_level_2]
+ SiteSetting.voice_screen_share_allowed_groups = Group::AUTO_GROUPS[:logged_in_users]
+
+ expect(described_class.for_user(member)).to eq(
+ can_publish_video: true,
+ can_screen_share: true,
+ )
+ expect(described_class.for_user(low_trust_user)).to eq(
+ can_publish_video: false,
+ can_screen_share: true,
+ )
+ end
+
+ it "denies an anonymous viewer" do
+ expect(described_class.for_user(nil)).to eq(described_class::NONE)
+ end
+
+ it "reuses the user's group ids across calls" do
+ SiteSetting.voice_video_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]
+ SiteSetting.voice_screen_share_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]
+ described_class.for_user(member)
+
+ queries = track_sql_queries { described_class.for_user(member) }
+
+ expect(queries).to be_empty
+ end
+ end
+
+ it "reads a whole roster without querying per user" do
+ users = Array.new(3) { Fabricate(:user) }
+ SiteSetting.voice_video_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]
+ SiteSetting.voice_screen_share_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]
+
+ queries = track_sql_queries { described_class.for_users(room, users) }
+
+ expect(queries.count { |sql| sql.include?("group_users") }).to eq(2)
+ end
+end
diff --git a/plugins/voice/spec/migrations/replace_voice_video_enabled_setting_spec.rb b/plugins/voice/spec/migrations/replace_voice_video_enabled_setting_spec.rb
new file mode 100644
index 00000000000..895da0df002
--- /dev/null
+++ b/plugins/voice/spec/migrations/replace_voice_video_enabled_setting_spec.rb
@@ -0,0 +1,65 @@
+# frozen_string_literal: true
+
+require Rails.root.join(
+ "plugins/voice/db/post_migrate/20261009144947_replace_voice_video_enabled_setting.rb",
+ )
+
+RSpec.describe ReplaceVoiceVideoEnabledSetting do
+ before do
+ @original_verbose = ActiveRecord::Migration.verbose
+ ActiveRecord::Migration.verbose = false
+ end
+
+ after { ActiveRecord::Migration.verbose = @original_verbose }
+
+ # The test provider keeps settings in memory; the migration reads the table.
+ def insert_old_setting(value)
+ DB.exec(
+ "INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('voice_video_enabled', :type, :value, NOW(), NOW())",
+ type: SiteSettings::TypeSupervisor.types[:bool],
+ value: value,
+ )
+ end
+
+ def stored(name)
+ DB.query_single("SELECT value FROM site_settings WHERE name = :name", name: name)
+ end
+
+ it "keeps video off for a site that had disabled it" do
+ insert_old_setting("f")
+
+ described_class.new.up
+
+ expect(stored("voice_video_allowed_groups")).to eq([""])
+ expect(stored("voice_screen_share_allowed_groups")).to eq([""])
+ expect(stored("voice_video_enabled")).to be_empty
+ end
+
+ it "leaves the new defaults in place for a site that had video on" do
+ insert_old_setting("t")
+
+ described_class.new.up
+
+ expect(stored("voice_video_allowed_groups")).to be_empty
+ expect(stored("voice_screen_share_allowed_groups")).to be_empty
+ expect(stored("voice_video_enabled")).to be_empty
+ end
+
+ it "writes nothing when the old setting was never stored" do
+ described_class.new.up
+
+ expect(stored("voice_video_allowed_groups")).to be_empty
+ end
+
+ it "does not overwrite a group list an admin already configured" do
+ insert_old_setting("f")
+ DB.exec(
+ "INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('voice_video_allowed_groups', :type, '13', NOW(), NOW())",
+ type: SiteSettings::TypeSupervisor.types[:group_list],
+ )
+
+ described_class.new.up
+
+ expect(stored("voice_video_allowed_groups")).to eq(["13"])
+ end
+end
diff --git a/plugins/voice/spec/models/voice/room_spec.rb b/plugins/voice/spec/models/voice/room_spec.rb
index ac0d64ce8e8..ac6cbb35125 100644
--- a/plugins/voice/spec/models/voice/room_spec.rb
+++ b/plugins/voice/spec/models/voice/room_spec.rb
@@ -109,35 +109,6 @@ RSpec.describe Voice::Room do
end
end
- describe "#video_allowed?" do
- before { SiteSetting.voice_video_enabled = true }
-
- it "is true for a stage room with video enabled" do
- room.update!(room_type: Voice::Room::ROOM_TYPE_STAGE, video_enabled: true)
-
- expect(room.video_allowed?).to eq(true)
- end
-
- it "is true for an open room with video enabled" do
- room.update!(room_type: Voice::Room::ROOM_TYPE_OPEN, video_enabled: true)
-
- expect(room.video_allowed?).to eq(true)
- end
-
- it "is false when the site setting is disabled" do
- SiteSetting.voice_video_enabled = false
- room.update!(video_enabled: true)
-
- expect(room.video_allowed?).to eq(false)
- end
-
- it "is false when the room has video disabled" do
- room.update!(video_enabled: false)
-
- expect(room.video_allowed?).to eq(false)
- end
- end
-
describe "membership predicates" do
it "reuses loaded memberships" do
creator = room.creator
diff --git a/plugins/voice/spec/requests/voice/rooms_controller_spec.rb b/plugins/voice/spec/requests/voice/rooms_controller_spec.rb
index 8f97e61141a..cba2d8cb52a 100644
--- a/plugins/voice/spec/requests/voice/rooms_controller_spec.rb
+++ b/plugins/voice/spec/requests/voice/rooms_controller_spec.rb
@@ -969,7 +969,6 @@ RSpec.describe Voice::RoomsController do
describe "#state" do
before do
- SiteSetting.voice_video_enabled = true
@participant_session_id = establish_presence!(room, user)
sign_in(user)
end
@@ -1040,8 +1039,8 @@ RSpec.describe Voice::RoomsController do
expect(metadata[:is_transcribing]).to eq(false)
end
- it "rejects video when the site setting is disabled" do
- SiteSetting.voice_video_enabled = false
+ it "rejects video when no group is allowed to share a camera" do
+ SiteSetting.voice_video_allowed_groups = ""
post "/voice/rooms/#{room.id}/state.json",
params: {
@@ -1052,6 +1051,31 @@ RSpec.describe Voice::RoomsController do
expect(response.status).to eq(403)
end
+ it "rejects screen sharing when no group is allowed to share a screen" do
+ SiteSetting.voice_screen_share_allowed_groups = ""
+
+ post "/voice/rooms/#{room.id}/state.json",
+ params: {
+ screen: true,
+ participant_session_id: @participant_session_id,
+ }
+
+ expect(response.status).to eq(403)
+ end
+
+ it "allows a camera when only screen sharing is disallowed" do
+ SiteSetting.voice_screen_share_allowed_groups = ""
+
+ post "/voice/rooms/#{room.id}/state.json",
+ params: {
+ video: true,
+ participant_session_id: @participant_session_id,
+ }
+
+ expect(response.status).to eq(204)
+ expect(Voice::ParticipantTracker.get_metadata(room.id, user.id)[:is_video_on]).to eq(true)
+ end
+
it "rejects video when the room has video disabled" do
room.update!(video_enabled: false)
@@ -1346,6 +1370,17 @@ RSpec.describe Voice::RoomsController do
participant_ids = response.parsed_body["participants"].map { |p| p["id"] }
expect(participant_ids).to include(private_room_member.id)
end
+
+ it "carries each participant's media entitlements, like the broadcast roster" do
+ SiteSetting.voice_video_allowed_groups = Group::AUTO_GROUPS[:logged_in_users]
+ SiteSetting.voice_screen_share_allowed_groups = ""
+ sign_in(private_room_member)
+
+ get "/voice/rooms/#{private_room.id}/participants.json"
+
+ entry = response.parsed_body["participants"].find { |p| p["id"] == private_room_member.id }
+ expect(entry).to include("can_publish_video" => true, "can_screen_share" => false)
+ end
end
describe "#heartbeat on a private room" do
diff --git a/plugins/voice/spec/serializers/site_serializer_spec.rb b/plugins/voice/spec/serializers/site_serializer_spec.rb
new file mode 100644
index 00000000000..7a3993ddf9c
--- /dev/null
+++ b/plugins/voice/spec/serializers/site_serializer_spec.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+RSpec.describe SiteSerializer do
+ fab!(:user)
+
+ before { SiteSetting.voice_enabled = true }
+
+ def voice_video_available
+ described_class.new(Site.new(user.guardian), scope: user.guardian, root: false).as_json[
+ :voice_video_available
+ ]
+ end
+
+ describe "#voice_video_available" do
+ it "is true when either capability has groups" do
+ SiteSetting.voice_video_allowed_groups = ""
+ SiteSetting.voice_screen_share_allowed_groups = Group::AUTO_GROUPS[:trust_level_1]
+
+ expect(voice_video_available).to eq(true)
+ end
+
+ it "is false when neither capability has groups" do
+ SiteSetting.voice_video_allowed_groups = ""
+ SiteSetting.voice_screen_share_allowed_groups = ""
+
+ expect(voice_video_available).to eq(false)
+ end
+ end
+end
diff --git a/plugins/voice/spec/serializers/voice/room_serializer_spec.rb b/plugins/voice/spec/serializers/voice/room_serializer_spec.rb
new file mode 100644
index 00000000000..0ae3052cc87
--- /dev/null
+++ b/plugins/voice/spec/serializers/voice/room_serializer_spec.rb
@@ -0,0 +1,81 @@
+# frozen_string_literal: true
+
+RSpec.describe Voice::RoomSerializer do
+ fab!(:user)
+ fab!(:room) { Fabricate(:voice_room, public: true) }
+
+ before do
+ SiteSetting.voice_enabled = true
+ SiteSetting.voice_allowed_groups =
+ "#{Group::AUTO_GROUPS[:anonymous_users]}|#{Group::AUTO_GROUPS[:logged_in_users]}"
+ end
+
+ def serialize(scope)
+ described_class.new(room, scope: scope, root: false).as_json
+ end
+
+ describe "roster media entitlements" do
+ fab!(:speaker, :user)
+
+ before do
+ Voice::ParticipantTracker.add(room.id, user.id)
+ Voice::ParticipantTracker.add(room.id, speaker.id)
+ end
+
+ # Mesh receivers decide what to play from the sender's entry, so every
+ # participant carries its own entitlements — including in the
+ # anonymously-scoped broadcasts.
+ it "stamps each participant with their own capabilities" do
+ SiteSetting.voice_screen_share_allowed_groups = ""
+
+ participants = serialize(Guardian.new(nil))[:active_participants]
+
+ expect(participants.size).to eq(2)
+ expect(participants.map { |p| p[:can_publish_video] }).to all(eq(true))
+ expect(participants.map { |p| p[:can_screen_share] }).to all(eq(false))
+ end
+
+ it "stamps nothing when the room has media disabled" do
+ room.update!(video_enabled: false)
+
+ participants = serialize(user.guardian)[:active_participants]
+
+ expect(participants.map { |p| p[:can_publish_video] }).to all(eq(false))
+ expect(participants.map { |p| p[:can_screen_share] }).to all(eq(false))
+ end
+ end
+
+ describe "media publish rights" do
+ it "reports each capability separately" do
+ SiteSetting.voice_screen_share_allowed_groups = ""
+
+ payload = serialize(user.guardian)
+
+ expect(payload[:video_allowed]).to eq(true)
+ expect(payload[:screen_share_allowed]).to eq(false)
+ end
+
+ # Directory broadcasts are serialized without a user; sending them as
+ # false would revoke every client's own rights on an unrelated update.
+ it "omits both for an anonymous scope, leaving the room's own flag" do
+ payload = serialize(Guardian.new(nil))
+
+ expect(payload).not_to have_key(:video_allowed)
+ expect(payload).not_to have_key(:screen_share_allowed)
+ expect(payload[:video_enabled]).to eq(true)
+ end
+
+ # The room flag travels in anonymous broadcasts the per-user rights can't
+ # follow, so a "no" folded in here would outlive the room's media coming
+ # back on.
+ it "leaves the room's own media flag to video_enabled" do
+ room.update!(video_enabled: false)
+
+ payload = serialize(user.guardian)
+
+ expect(payload[:video_allowed]).to eq(true)
+ expect(payload[:screen_share_allowed]).to eq(true)
+ expect(payload[:video_enabled]).to eq(false)
+ end
+ end
+end
diff --git a/plugins/voice/spec/services/voice/room_broadcaster_spec.rb b/plugins/voice/spec/services/voice/room_broadcaster_spec.rb
index 29c13908d61..f3f00df1e0d 100644
--- a/plugins/voice/spec/services/voice/room_broadcaster_spec.rb
+++ b/plugins/voice/spec/services/voice/room_broadcaster_spec.rb
@@ -77,6 +77,21 @@ RSpec.describe Voice::RoomBroadcaster do
expect(messages.first.user_ids).to contain_exactly(private_room.creator_id, participant.id)
end
+
+ it "stamps each participant with their own media entitlements" do
+ SiteSetting.voice_video_allowed_groups = Group::AUTO_GROUPS[:logged_in_users]
+ SiteSetting.voice_screen_share_allowed_groups = ""
+ Voice::ParticipantTracker.add(room.id, participant.id)
+
+ messages =
+ MessageBus.track_publish(Voice.room_channel(room.id)) do
+ described_class.publish_participants(room)
+ end
+
+ expect(messages.first.data[:participants]).to contain_exactly(
+ include(id: participant.id, can_publish_video: true, can_screen_share: false),
+ )
+ end
end
describe ".publish_hand_raise" do
diff --git a/plugins/voice/spec/system/voice_livekit_spec.rb b/plugins/voice/spec/system/voice_livekit_spec.rb
index c7c22edaccd..5bf2c81018d 100644
--- a/plugins/voice/spec/system/voice_livekit_spec.rb
+++ b/plugins/voice/spec/system/voice_livekit_spec.rb
@@ -40,7 +40,6 @@ describe "Voice LiveKit rooms", if: ENV["VOICE_LIVEKIT_TEST_URL"] do
SiteSetting.voice_mesh_privacy_warning_enabled = false
SiteSetting.voice_allowed_groups =
"#{Group::AUTO_GROUPS[:anonymous_users]}|#{Group::AUTO_GROUPS[:logged_in_users]}"
- SiteSetting.voice_video_enabled = true
# The policy validator requires url + key + secret to be present first.
SiteSetting.voice_livekit_url = ENV["VOICE_LIVEKIT_TEST_URL"]
diff --git a/plugins/voice/spec/system/voice_rooms_spec.rb b/plugins/voice/spec/system/voice_rooms_spec.rb
index 7b042dd2b9c..9496bb1bfef 100644
--- a/plugins/voice/spec/system/voice_rooms_spec.rb
+++ b/plugins/voice/spec/system/voice_rooms_spec.rb
@@ -115,7 +115,6 @@ describe "Voice rooms" do
end
it "can publish a fake camera stream on the room page" do
- SiteSetting.voice_video_enabled = true
install_voice_fake_media
visit("/voice/r/#{room.slug}")
@@ -131,7 +130,6 @@ describe "Voice rooms" do
end
it "switches between presentation and tiled layouts from the menu" do
- SiteSetting.voice_video_enabled = true
install_voice_fake_media
visit("/voice/r/#{room.slug}")
@@ -147,7 +145,6 @@ describe "Voice rooms" do
end
it "keeps the active call in a widget after switching to widget mode" do
- SiteSetting.voice_video_enabled = true
install_voice_fake_media
visit("/voice/r/#{room.slug}")
@@ -174,7 +171,6 @@ describe "Voice rooms" do
end
it "can stop video and leave the call from the persistent widget" do
- SiteSetting.voice_video_enabled = true
install_voice_fake_media
visit("/voice/r/#{room.slug}")
@@ -194,7 +190,6 @@ describe "Voice rooms" do
end
it "opens room actions from the widget overflow menu" do
- SiteSetting.voice_video_enabled = true
install_voice_fake_media
visit("/voice/r/#{room.slug}")
@@ -215,7 +210,6 @@ describe "Voice rooms" do
end
it "shows remote fake video when another user publishes a camera stream" do
- SiteSetting.voice_video_enabled = true
other_user.activate
other_user.update!(trust_level: TrustLevel[2])
Group.refresh_automatic_groups!
@@ -270,7 +264,6 @@ describe "Voice rooms" do
end
it "keeps remote video attached in widget mode" do
- SiteSetting.voice_video_enabled = true
other_user.activate
other_user.update!(trust_level: TrustLevel[2])
Group.refresh_automatic_groups!
@@ -333,10 +326,7 @@ describe "Voice rooms" do
)
end
- before do
- other_user.activate
- SiteSetting.voice_video_enabled = true
- end
+ before { other_user.activate }
it "lets a joined moderator publish camera video while a listener gets no capture buttons" do
using_session(:moderator) do
diff --git a/plugins/voice/spec/system/voice_stage_speak_queue_spec.rb b/plugins/voice/spec/system/voice_stage_speak_queue_spec.rb
index 4fa61ce87da..3e05de608fb 100644
--- a/plugins/voice/spec/system/voice_stage_speak_queue_spec.rb
+++ b/plugins/voice/spec/system/voice_stage_speak_queue_spec.rb
@@ -27,7 +27,6 @@ describe "Voice stage speak queue" do
SiteSetting.voice_mesh_privacy_warning_enabled = false
SiteSetting.voice_allowed_groups =
"#{Group::AUTO_GROUPS[:anonymous_users]}|#{Group::AUTO_GROUPS[:logged_in_users]}"
- SiteSetting.voice_video_enabled = true
end
def join_room(user)
diff --git a/plugins/voice/spec/system/voice_video_settings_spec.rb b/plugins/voice/spec/system/voice_video_settings_spec.rb
index 696438f4f2f..de5f4727a65 100644
--- a/plugins/voice/spec/system/voice_video_settings_spec.rb
+++ b/plugins/voice/spec/system/voice_video_settings_spec.rb
@@ -17,7 +17,6 @@ describe "Voice video settings" do
SiteSetting.voice_mesh_privacy_warning_enabled = false
SiteSetting.voice_allowed_groups =
"#{Group::AUTO_GROUPS[:anonymous_users]}|#{Group::AUTO_GROUPS[:logged_in_users]}"
- SiteSetting.voice_video_enabled = true
sign_in(user)
install_voice_fake_media
end
@@ -41,6 +40,24 @@ describe "Voice video settings" do
expect(page).to have_css(".voice-video-settings-modal")
end
+ it "hides the screen share button from groups not allowed to share a screen" do
+ SiteSetting.voice_screen_share_allowed_groups = ""
+
+ join_room
+
+ expect(page).to have_button(I18n.t("js.voice.video.camera_on"))
+ expect(page).to have_no_button(I18n.t("js.voice.video.screen_share_start"))
+ end
+
+ it "hides the camera button from groups not allowed to share a camera" do
+ SiteSetting.voice_video_allowed_groups = ""
+
+ join_room
+
+ expect(page).to have_button(I18n.t("js.voice.video.screen_share_start"))
+ expect(page).to have_no_button(I18n.t("js.voice.video.camera_on"))
+ end
+
it "offers voice and video settings from the call menus" do
join_room
diff --git a/plugins/voice/test/javascripts/integration/components/voice-room-form-test.gjs b/plugins/voice/test/javascripts/integration/components/voice-room-form-test.gjs
index fb091cd6279..d1d77938bdd 100644
--- a/plugins/voice/test/javascripts/integration/components/voice-room-form-test.gjs
+++ b/plugins/voice/test/javascripts/integration/components/voice-room-form-test.gjs
@@ -20,7 +20,7 @@ module("Integration | Component | voice-room-form", function (hooks) {
hooks.beforeEach(function () {
this.siteSettings.chat_enabled = true;
this.siteSettings.voice_chat_enabled = true;
- this.siteSettings.voice_video_enabled = false;
+ this.owner.lookup("service:site").set("voice_video_available", false);
this.owner.unregister("service:chat-api");
this.owner.register("service:chat-api", ChatApiStub);
@@ -95,6 +95,26 @@ module("Integration | Component | voice-room-form", function (hooks) {
assert.dom('[data-name="livekit_enabled"]').doesNotExist();
});
+ test("shows the room's media toggle only when a group may publish", async function (assert) {
+ this.room = {
+ name: "Chill",
+ description: "",
+ public: true,
+ room_type: "open",
+ max_participants: null,
+ video_enabled: true,
+ chat_channel_id: null,
+ chat_idle_minutes: 15,
+ };
+
+ await render(<template><VoiceRoomForm @room={{this.room}} /></template>);
+ assert.dom('[data-name="video_enabled"]').doesNotExist();
+
+ this.owner.lookup("service:site").set("voice_video_available", true);
+ await render(<template><VoiceRoomForm @room={{this.room}} /></template>);
+ assert.dom('[data-name="video_enabled"]').exists();
+ });
+
test("hides the chat settings when no chat channel is linked", async function (assert) {
this.room = {
name: "Chill",
diff --git a/plugins/voice/test/javascripts/integration/components/voice-room-page-test.gjs b/plugins/voice/test/javascripts/integration/components/voice-room-page-test.gjs
index a52a1018142..96d86e3c619 100644
--- a/plugins/voice/test/javascripts/integration/components/voice-room-page-test.gjs
+++ b/plugins/voice/test/javascripts/integration/components/voice-room-page-test.gjs
@@ -40,7 +40,15 @@ class VoiceWebrtcStub extends Service {
return true;
}
- canPublishVideo() {
+ screenShareAllowedIn() {
+ return true;
+ }
+
+ canPublishCamera() {
+ return true;
+ }
+
+ canPublishScreen() {
return true;
}
diff --git a/plugins/voice/test/javascripts/integration/components/voice/call-widget-test.gjs b/plugins/voice/test/javascripts/integration/components/voice/call-widget-test.gjs
index 59daadb1d71..afc701e79e9 100644
--- a/plugins/voice/test/javascripts/integration/components/voice/call-widget-test.gjs
+++ b/plugins/voice/test/javascripts/integration/components/voice/call-widget-test.gjs
@@ -55,7 +55,15 @@ class VoiceWebrtcStub extends Service {
return true;
}
- canPublishVideo() {
+ screenShareAllowedIn() {
+ return true;
+ }
+
+ canPublishCamera() {
+ return true;
+ }
+
+ canPublishScreen() {
return true;
}
diff --git a/plugins/voice/test/javascripts/unit/lib/stage-roles-test.js b/plugins/voice/test/javascripts/unit/lib/stage-roles-test.js
new file mode 100644
index 00000000000..6928c40c6a7
--- /dev/null
+++ b/plugins/voice/test/javascripts/unit/lib/stage-roles-test.js
@@ -0,0 +1,118 @@
+import { module, test } from "qunit";
+import {
+ participantEntitledToMedia,
+ remoteTrackAllowed,
+} from "discourse/plugins/voice/discourse/lib/voice/stage-roles";
+
+function room(participant) {
+ return {
+ room_type: "open",
+ video_enabled: true,
+ active_participants: [{ id: 2, role: "participant", ...participant }],
+ };
+}
+
+const videoTrack = { kind: "video" };
+const audioTrack = { kind: "audio" };
+
+module("Voice | Unit | Lib | stage-roles", function () {
+ test("a mesh video track needs the sender's entitlement", function (assert) {
+ const cases = [
+ [{ is_video_on: true, can_publish_video: true }, true, "entitled camera"],
+ [
+ { is_video_on: true, can_publish_video: false },
+ false,
+ "camera without the entitlement",
+ ],
+ [
+ { is_screen_sharing: true, can_screen_share: true },
+ true,
+ "entitled screen share",
+ ],
+ [
+ { is_screen_sharing: true, can_screen_share: false },
+ false,
+ "screen share without the entitlement",
+ ],
+ [
+ { can_publish_video: true },
+ true,
+ "an idle entitled sender, whose pre-negotiated track arrives before it publishes",
+ ],
+ [{}, false, "no entitlement at all"],
+ ];
+
+ for (const [participant, expected, label] of cases) {
+ assert.strictEqual(
+ remoteTrackAllowed(room(participant), 2, videoTrack, [], {
+ mesh: true,
+ }),
+ expected,
+ label
+ );
+ }
+ });
+
+ test("bare screen audio needs the screen entitlement specifically", function (assert) {
+ assert.true(
+ remoteTrackAllowed(room({ can_screen_share: true }), 2, audioTrack, [], {
+ mesh: true,
+ }),
+ "an entitled screen sharer's content audio plays"
+ );
+
+ assert.false(
+ remoteTrackAllowed(
+ room({ is_video_on: true, can_publish_video: true }),
+ 2,
+ audioTrack,
+ [],
+ { mesh: true }
+ ),
+ "a camera entitlement does not carry screen audio"
+ );
+
+ assert.true(
+ remoteTrackAllowed(room({}), 2, audioTrack, [{ id: "mic-stream" }], {
+ mesh: true,
+ }),
+ "mic audio, which arrives with a stream, is untouched by media entitlements"
+ );
+ });
+
+ test("entitlements are not required off the mesh, where the SFU enforces them", function (assert) {
+ assert.true(
+ remoteTrackAllowed(room({ is_video_on: true }), 2, videoTrack, []),
+ "a LiveKit subscription may land before the roster broadcast"
+ );
+ });
+
+ test("the room's own media flag still overrides an entitled sender", function (assert) {
+ const disabled = room({ is_video_on: true, can_publish_video: true });
+ disabled.video_enabled = false;
+
+ assert.false(
+ remoteTrackAllowed(disabled, 2, videoTrack, [], { mesh: true }),
+ "a room with media disabled plays no video"
+ );
+ });
+
+ test("a stage listener publishes nothing, however entitled", function (assert) {
+ const stage = room({
+ role: "listener",
+ is_video_on: true,
+ can_publish_video: true,
+ });
+ stage.room_type = "stage";
+
+ assert.false(
+ remoteTrackAllowed(stage, 2, videoTrack, [], { mesh: true }),
+ "the role gate applies before entitlements matter"
+ );
+ });
+
+ test("participantEntitledToMedia answers for a missing participant", function (assert) {
+ assert.false(participantEntitledToMedia(undefined));
+ assert.false(participantEntitledToMedia(null, { screenOnly: true }));
+ });
+});
diff --git a/plugins/voice/test/javascripts/unit/services/voice-webrtc-livekit-test.js b/plugins/voice/test/javascripts/unit/services/voice-webrtc-livekit-test.js
index 8f46f44aedb..7d2b39b2a8c 100644
--- a/plugins/voice/test/javascripts/unit/services/voice-webrtc-livekit-test.js
+++ b/plugins/voice/test/javascripts/unit/services/voice-webrtc-livekit-test.js
@@ -491,7 +491,6 @@ module("Voice | Unit | Service | voice-webrtc-livekit", function (hooks) {
this.keyValueStore.remove(this.cameraPreferenceKey);
this.siteSettings = this.owner.lookup("service:site-settings");
this.siteSettings.voice_auto_status_enabled = true;
- this.siteSettings.voice_video_enabled = true;
this.siteSettings.voice_video_max_publishers = 4;
localStorage.removeItem("voice:noise-suppression");
localStorage.removeItem("voice:noise-suppression-mode");
@@ -508,6 +507,8 @@ module("Voice | Unit | Service | voice-webrtc-livekit", function (hooks) {
name: "Voice",
room_type: "open",
video_enabled: true,
+ video_allowed: true,
+ screen_share_allowed: true,
membership: { role_name: "participant" },
active_participants: [
{ id: this.currentUser.id, role: "participant" },
diff --git a/plugins/voice/test/javascripts/unit/services/voice-webrtc-test.js b/plugins/voice/test/javascripts/unit/services/voice-webrtc-test.js
index 83e384802bd..753b760e8e3 100644
--- a/plugins/voice/test/javascripts/unit/services/voice-webrtc-test.js
+++ b/plugins/voice/test/javascripts/unit/services/voice-webrtc-test.js
@@ -1240,10 +1240,15 @@ module("Voice | Unit | Service | voice-webrtc", function (hooks) {
this.room.room_type = "open";
this.room.membership.role_name = "participant";
- this.room.video_allowed = false;
+ this.room.video_enabled = false;
this.room.active_participants = [
{ id: this.currentUser.id, role: "participant" },
- { id: 2, role: "participant" },
+ {
+ id: 2,
+ role: "participant",
+ is_video_on: true,
+ can_publish_video: true,
+ },
];
try {
@@ -1261,7 +1266,7 @@ module("Voice | Unit | Service | voice-webrtc", function (hooks) {
"video is dropped while the room's media policy disallows it"
);
- this.room.video_allowed = true;
+ this.room.video_enabled = true;
pc.ontrack({ streams: [], track: createFakeTrack("real-cam", "video") });
await wait(10);
@@ -1278,6 +1283,267 @@ module("Voice | Unit | Service | voice-webrtc", function (hooks) {
}
});
+ module("mesh media entitlements on the roster", function (nestedHooks) {
+ nestedHooks.beforeEach(function () {
+ this.room.room_type = "open";
+ this.room.membership.role_name = "participant";
+ this.room.video_enabled = true;
+
+ this.emitPeer = (peer) => {
+ const participants = [
+ { id: this.currentUser.id, role: "participant" },
+ { id: 2, role: "participant", ...peer },
+ ];
+ this.room.active_participants = participants;
+ this.rooms.emit(1, { type: "participants", participants });
+ };
+
+ this.peerTrackIds = () => ({
+ // Registration order depends on when the roster lands relative to
+ // ontrack, which isn't what these tests are about.
+ media: (this.subject.remoteStreamFor(1, 2)?.getTracks() || [])
+ .map((track) => track.id)
+ .sort(),
+ screenAudio: this.subject.remoteScreenAudioStreams
+ .flatMap((stream) => stream.getTracks())
+ .map((track) => track.id),
+ });
+
+ this.audioEnvironment = installFakeAudioEnvironment({
+ rawStream: createFakeStream("raw-stream", createFakeTrack("raw-track")),
+ processedStream: createFakeStream(
+ "processed-stream",
+ createFakeTrack("processed-track")
+ ),
+ });
+ });
+
+ nestedHooks.afterEach(function () {
+ this.audioEnvironment.restore();
+ });
+
+ // Roster handling is async; compare as strings so a failure reports the
+ // actual track ids rather than "[object Object]".
+ async function assertPeerTracks(context, assert, expected, label) {
+ const matches = () =>
+ JSON.stringify(context.peerTrackIds()) === JSON.stringify(expected);
+ await waitUntil(matches, 500).catch(() => {});
+
+ assert.strictEqual(
+ JSON.stringify(context.peerTrackIds()),
+ JSON.stringify(expected),
+ label
+ );
+ }
+
+ async function joinWithSharingPeer(context) {
+ context.room.active_participants = [
+ { id: context.currentUser.id, role: "participant" },
+ {
+ id: 2,
+ role: "participant",
+ is_screen_sharing: true,
+ can_publish_video: true,
+ can_screen_share: true,
+ },
+ ];
+
+ await context.subject.join(context.room);
+ await wait(50);
+
+ const pc = await answerRemoteOffer(context, 2);
+ const micTrack = createFakeTrack("peer-2-mic");
+ pc.ontrack({
+ streams: [createFakeStream("peer-2-stream", micTrack)],
+ track: micTrack,
+ });
+
+ context.emitPeer({
+ is_screen_sharing: true,
+ can_publish_video: true,
+ can_screen_share: true,
+ });
+ }
+
+ test("a lost entitlement drops video and screen audio but keeps the mic", async function (assert) {
+ assert.timeout(2000);
+ await joinWithSharingPeer(this);
+
+ await assertPeerTracks(
+ this,
+ assert,
+ {
+ media: ["peer-2-mic", "video-receiver-1"],
+ screenAudio: ["audio-receiver-2"],
+ },
+ "an entitled sharer's screen and its audio play"
+ );
+
+ this.emitPeer({ is_screen_sharing: true });
+
+ await assertPeerTracks(
+ this,
+ assert,
+ { media: ["peer-2-mic"], screenAudio: [] },
+ "only the microphone survives losing both entitlements"
+ );
+ });
+
+ test("losing only screen sharing while sharing drops the screen, not the mic", async function (assert) {
+ assert.timeout(2000);
+ await joinWithSharingPeer(this);
+
+ this.emitPeer({ is_screen_sharing: true, can_publish_video: true });
+
+ await assertPeerTracks(
+ this,
+ assert,
+ { media: ["peer-2-mic"], screenAudio: [] },
+ "the video m-line is carrying the screen, so it goes too"
+ );
+
+ this.emitPeer({ is_video_on: true, can_publish_video: true });
+
+ await assertPeerTracks(
+ this,
+ assert,
+ { media: ["peer-2-mic", "video-receiver-1"], screenAudio: [] },
+ "switching to the still-allowed camera brings the video back"
+ );
+ });
+
+ test("a sender who only stops publishing keeps its idle tracks", async function (assert) {
+ assert.timeout(2000);
+ await joinWithSharingPeer(this);
+
+ this.emitPeer({ can_publish_video: true, can_screen_share: true });
+
+ await assertPeerTracks(
+ this,
+ assert,
+ {
+ media: ["peer-2-mic", "video-receiver-1"],
+ screenAudio: ["audio-receiver-2"],
+ },
+ "nothing is revoked, so the tracks stay registered for the next share"
+ );
+ });
+
+ test("screen audio comes back when a revoked entitlement is restored", async function (assert) {
+ assert.timeout(2000);
+ await joinWithSharingPeer(this);
+
+ this.emitPeer({ is_screen_sharing: true, can_publish_video: true });
+ await assertPeerTracks(
+ this,
+ assert,
+ { media: ["peer-2-mic"], screenAudio: [] },
+ "revoked"
+ );
+
+ this.emitPeer({
+ is_screen_sharing: true,
+ can_publish_video: true,
+ can_screen_share: true,
+ });
+
+ await assertPeerTracks(
+ this,
+ assert,
+ {
+ media: ["peer-2-mic", "video-receiver-1"],
+ screenAudio: ["audio-receiver-2"],
+ },
+ "the pre-negotiated screen and its audio are registered again"
+ );
+ });
+ });
+
+ test("re-enabling a room's media restores publishing without a fresh payload", function (assert) {
+ this.room.room_type = "open";
+ this.room.membership.role_name = "participant";
+ this.room.video_allowed = true;
+ this.room.screen_share_allowed = true;
+ this.room.video_enabled = false;
+
+ assert.false(this.subject.videoAllowedIn(this.room), "off with the room");
+ assert.false(this.subject.screenShareAllowedIn(this.room));
+
+ this.room.video_enabled = true;
+
+ assert.true(
+ this.subject.videoAllowedIn(this.room),
+ "the per-user right was kept, so the room flag alone turns it back on"
+ );
+ assert.true(this.subject.screenShareAllowedIn(this.room));
+ });
+
+ test("keeps a pre-negotiated video track alive until its sender may publish", async function (assert) {
+ assert.timeout(2000);
+
+ const rawTrack = createFakeTrack("raw-track");
+ const rawStream = createFakeStream("raw-stream", rawTrack);
+ const audioEnvironment = installFakeAudioEnvironment({
+ rawStream,
+ processedStream: createFakeStream(
+ "processed-stream",
+ createFakeTrack("processed-track")
+ ),
+ });
+
+ this.room.room_type = "open";
+ this.room.membership.role_name = "participant";
+ this.room.video_enabled = true;
+ this.room.active_participants = [
+ { id: this.currentUser.id, role: "participant" },
+ { id: 2, role: "participant" },
+ ];
+
+ try {
+ await this.subject.join(this.room);
+ await wait(50);
+
+ const pc = await answerRemoteOffer(this, 2);
+
+ let stopped = false;
+ const idleTrack = createFakeTrack("idle-cam", "video");
+ idleTrack.stop = () => (stopped = true);
+ pc.ontrack({ streams: [], track: idleTrack });
+ await wait(10);
+
+ assert.strictEqual(
+ this.subject.remoteStreamsFor(1).length,
+ 0,
+ "an unentitled sender's video is not registered"
+ );
+ assert.false(
+ stopped,
+ "the receiver track survives, since the transceiver never delivers another"
+ );
+
+ this.room.active_participants = [
+ { id: this.currentUser.id, role: "participant" },
+ { id: 2, role: "participant", can_publish_video: true },
+ ];
+ pc.ontrack({
+ streams: [],
+ track: createFakeTrack("entitled-idle-cam", "video"),
+ });
+ await wait(10);
+
+ assert.true(
+ this.subject
+ .remoteStreamsFor(1)
+ .some((stream) =>
+ stream.getTracks().some((track) => track.id === "entitled-idle-cam")
+ ),
+ "an entitled sender's video registers before it starts publishing"
+ );
+ } finally {
+ audioEnvironment.restore();
+ }
+ });
+
test("a roster refresh drops media from a participant demoted to listener", async function (assert) {
assert.timeout(2000);
@@ -2087,7 +2353,8 @@ module("Voice | Unit | Service | voice-webrtc", function (hooks) {
});
test("leaving the room page stops an active camera publication", async function (assert) {
- this.siteSettings.voice_video_enabled = true;
+ this.room.video_allowed = true;
+ this.room.screen_share_allowed = true;
this.siteSettings.voice_video_max_publishers = 8;
this.room.room_type = "open";
@@ -2214,7 +2481,8 @@ module("Voice | Unit | Service | voice-webrtc", function (hooks) {
}
function setupCameraRoom(context) {
- context.siteSettings.voice_video_enabled = true;
+ context.room.video_allowed = true;
+ context.room.screen_share_allowed = true;
context.siteSettings.voice_video_max_publishers = 8;
context.room.room_type = "open";
@@ -3026,14 +3294,12 @@ module("Voice | Unit | Service | voice-webrtc", function (hooks) {
test("remote camera start exposes the negotiated video track without a refresh", async function (assert) {
assert.timeout(2000);
- this.siteSettings.voice_video_enabled = true;
+ this.room.video_allowed = true;
+ this.room.screen_share_allowed = true;
this.siteSettings.voice_video_max_publishers = 8;
this.room.room_type = "open";
this.room.video_enabled = true;
- // The serializer's combined room+site flag; the receive-side track
- // policy consults it before registering the remote video track.
- this.room.video_allowed = true;
this.room.membership = { role_name: "participant" };
this.room.active_participants = [
{ id: this.currentUser.id, role: "participant" },
@@ -3071,6 +3337,7 @@ module("Voice | Unit | Service | voice-webrtc", function (hooks) {
role: "participant",
is_video_on: true,
is_screen_sharing: false,
+ can_publish_video: true,
},
],
});
@@ -3091,7 +3358,8 @@ module("Voice | Unit | Service | voice-webrtc", function (hooks) {
});
test("videoAllowedIn denies a stage listener", function (assert) {
- this.siteSettings.voice_video_enabled = true;
+ this.room.video_allowed = true;
+ this.room.screen_share_allowed = true;
this.room.video_enabled = true;
this.room.active_participants = [
{ id: this.currentUser.id, role: "listener" },
@@ -3105,7 +3373,8 @@ module("Voice | Unit | Service | voice-webrtc", function (hooks) {
});
test("videoAllowedIn allows a stage speaker", function (assert) {
- this.siteSettings.voice_video_enabled = true;
+ this.room.video_allowed = true;
+ this.room.screen_share_allowed = true;
this.room.video_enabled = true;
this.room.active_participants = [
{ id: this.currentUser.id, role: "speaker" },
@@ -3119,7 +3388,8 @@ module("Voice | Unit | Service | voice-webrtc", function (hooks) {
});
test("videoAllowedIn allows a stage moderator", function (assert) {
- this.siteSettings.voice_video_enabled = true;
+ this.room.video_allowed = true;
+ this.room.screen_share_allowed = true;
this.room.video_enabled = true;
this.room.active_participants = [
{ id: this.currentUser.id, role: "moderator" },
@@ -3133,7 +3403,7 @@ module("Voice | Unit | Service | voice-webrtc", function (hooks) {
});
test("videoAllowedIn still requires the room's video flag for a stage speaker", function (assert) {
- this.siteSettings.voice_video_enabled = true;
+ this.room.video_allowed = true;
this.room.video_enabled = false;
this.room.active_participants = [
{ id: this.currentUser.id, role: "speaker" },
@@ -3147,7 +3417,8 @@ module("Voice | Unit | Service | voice-webrtc", function (hooks) {
});
test("videoAllowedIn does not role-gate open rooms", function (assert) {
- this.siteSettings.voice_video_enabled = true;
+ this.room.video_allowed = true;
+ this.room.screen_share_allowed = true;
this.room.room_type = "open";
this.room.video_enabled = true;
this.room.active_participants = [
@@ -3161,6 +3432,47 @@ module("Voice | Unit | Service | voice-webrtc", function (hooks) {
);
});
+ test("camera and screen sharing are allowed independently", function (assert) {
+ this.room.room_type = "open";
+ this.room.video_enabled = true;
+ this.room.video_allowed = true;
+ this.room.screen_share_allowed = false;
+ this.room.active_participants = [
+ { id: this.currentUser.id, role: "participant" },
+ ];
+
+ assert.true(
+ this.subject.videoAllowedIn(this.room),
+ "the camera follows its own server-granted right"
+ );
+ assert.false(
+ this.subject.screenShareAllowedIn(this.room),
+ "screen sharing follows its own server-granted right"
+ );
+
+ this.room.video_allowed = false;
+ this.room.screen_share_allowed = true;
+
+ assert.false(this.subject.videoAllowedIn(this.room), "camera revoked");
+ assert.true(
+ this.subject.screenShareAllowedIn(this.room),
+ "screen sharing granted"
+ );
+ });
+
+ test("a room with media disabled overrides both granted rights", function (assert) {
+ this.room.room_type = "open";
+ this.room.video_enabled = false;
+ this.room.video_allowed = true;
+ this.room.screen_share_allowed = true;
+ this.room.active_participants = [
+ { id: this.currentUser.id, role: "participant" },
+ ];
+
+ assert.false(this.subject.videoAllowedIn(this.room));
+ assert.false(this.subject.screenShareAllowedIn(this.room));
+ });
+
function createDeviceTrack(id, deviceId) {
return {
id,