Remove opt-in media enable
This commit is contained in:
parent
c6695b4e8e
commit
38099aeb3c
@ -782,36 +782,9 @@ const MediaAgent = (props: MediaAgentProps) => {
|
||||
id: t.id,
|
||||
});
|
||||
|
||||
// Do NOT force-enable the original local tracks for bot peers.
|
||||
// For privacy and principle of least surprise, respect the local user's
|
||||
// muted/video state. If a bot is added and needs media, mark a pending
|
||||
// consent on the local peer so the UI can prompt the user.
|
||||
if (peer.peer_name.includes("-bot")) {
|
||||
try {
|
||||
const localPeerId = session.id;
|
||||
if (updatedPeers[localPeerId]) {
|
||||
const existingPending =
|
||||
(updatedPeers[localPeerId].attributes && updatedPeers[localPeerId].attributes.pendingBotConsent) || [];
|
||||
const botName = peer.peer_name;
|
||||
if (!existingPending.includes(botName)) {
|
||||
const newPending = [...existingPending, botName];
|
||||
updatedPeers[localPeerId] = {
|
||||
...updatedPeers[localPeerId],
|
||||
attributes: {
|
||||
...updatedPeers[localPeerId].attributes,
|
||||
pendingBotConsent: newPending,
|
||||
},
|
||||
};
|
||||
console.log(
|
||||
`media-agent - addPeer:${peer.peer_name} Marked pending bot consent for local user:`,
|
||||
newPending
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(`media-agent - addPeer: failed to mark pending bot consent`, e);
|
||||
}
|
||||
}
|
||||
// Respect the local user's muted/video state. Do not force-enable or
|
||||
// mark pending consent for bots here. The local user's track.enabled
|
||||
// state (set above) will be used when adding tracks to the connection.
|
||||
|
||||
// Add the existing track to the connection and rely on the track.enabled
|
||||
// value which was set above based on the local peer's muted/video state.
|
||||
@ -1021,17 +994,6 @@ const MediaAgent = (props: MediaAgentProps) => {
|
||||
updatedPeers[peer_id].connection = undefined;
|
||||
}
|
||||
|
||||
// Also clear any pending bot consent references for this peer name on the local peer
|
||||
try {
|
||||
const localPeer = updatedPeers[session.id];
|
||||
if (localPeer && localPeer.attributes && localPeer.attributes.pendingBotConsent) {
|
||||
const pending = localPeer.attributes.pendingBotConsent.filter((b: string) => b !== peer_name);
|
||||
localPeer.attributes.pendingBotConsent = pending;
|
||||
}
|
||||
} catch (e) {
|
||||
// session may not be available in this closure; ignore safely
|
||||
}
|
||||
|
||||
setPeers(updatedPeers);
|
||||
},
|
||||
[peers, setPeers]
|
||||
@ -1555,46 +1517,7 @@ const MediaControl: React.FC<MediaControlProps> = ({ isSelf, peer, className })
|
||||
);
|
||||
|
||||
// Handlers for bot consent prompts (local user only)
|
||||
const handleAllowBot = useCallback(
|
||||
(botName: string) => {
|
||||
if (!peer || !peer.local) return;
|
||||
|
||||
// Clear pending for this bot and unmute/share media
|
||||
const pending = (peer.attributes && peer.attributes.pendingBotConsent) || [];
|
||||
const remaining = pending.filter((b: string) => b !== botName);
|
||||
|
||||
peer.attributes = {
|
||||
...(peer.attributes || {}),
|
||||
pendingBotConsent: remaining,
|
||||
};
|
||||
|
||||
// Share: unmute and enable video (you might want different behaviour)
|
||||
setMuted(false);
|
||||
setVideoOn(true);
|
||||
peer.muted = false;
|
||||
peer.video_on = true;
|
||||
|
||||
console.log(`media-agent - User allowed ${botName} to receive media`);
|
||||
// Note: MediaAgent.addPeer uses the current media.getTracks().enabled state when adding tracks;
|
||||
// existing connections won't be retroactively changed here. For a nicer UX we could trigger
|
||||
// renegotiation for that bot connection, but keep this minimal for now.
|
||||
},
|
||||
[peer]
|
||||
);
|
||||
|
||||
const handleDenyBot = useCallback(
|
||||
(botName: string) => {
|
||||
if (!peer || !peer.local) return;
|
||||
const pending = (peer.attributes && peer.attributes.pendingBotConsent) || [];
|
||||
const remaining = pending.filter((b: string) => b !== botName);
|
||||
peer.attributes = {
|
||||
...(peer.attributes || {}),
|
||||
pendingBotConsent: remaining,
|
||||
};
|
||||
console.log(`media-agent - User denied ${botName} access to media`);
|
||||
},
|
||||
[peer]
|
||||
);
|
||||
// No bot consent handlers — policy: do not override local mute/video state.
|
||||
|
||||
// Snap-back functionality
|
||||
const checkSnapBack = (x: number, y: number) => {
|
||||
@ -1700,44 +1623,7 @@ const MediaControl: React.FC<MediaControlProps> = ({ isSelf, peer, className })
|
||||
muted={peer.local || muted}
|
||||
/>
|
||||
<WebRTCStatus isNegotiating={peer.isNegotiating || false} connectionState={peer.connectionState} />
|
||||
{/* If this is the local user's UI and there are pending bot consent requests, show them */}
|
||||
{peer.local && peer.attributes?.pendingBotConsent && peer.attributes.pendingBotConsent.length > 0 && (
|
||||
<div
|
||||
style={{
|
||||
padding: "0.5rem",
|
||||
background: "#222",
|
||||
color: "#fff",
|
||||
marginTop: "0.5rem",
|
||||
borderRadius: 4,
|
||||
}}
|
||||
>
|
||||
<div style={{ fontSize: "0.9rem", marginBottom: "0.25rem" }}>Bots requesting media access:</div>
|
||||
{peer.attributes.pendingBotConsent.map((bot: string) => (
|
||||
<div
|
||||
key={bot}
|
||||
style={{ display: "flex", gap: "0.5rem", alignItems: "center", marginBottom: "0.25rem" }}
|
||||
>
|
||||
<div style={{ flex: 1 }}>{bot}</div>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handleAllowBot(bot);
|
||||
}}
|
||||
>
|
||||
Allow
|
||||
</button>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handleDenyBot(bot);
|
||||
}}
|
||||
>
|
||||
Deny
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<WebRTCStatus isNegotiating={peer.isNegotiating || false} connectionState={peer.connectionState} />
|
||||
</>
|
||||
)
|
||||
) : (
|
||||
|
Loading…
x
Reference in New Issue
Block a user