-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathNearbyAudioBindingSystem.cs
More file actions
78 lines (68 loc) · 3.35 KB
/
Copy pathNearbyAudioBindingSystem.cs
File metadata and controls
78 lines (68 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using Arch.Core;
using Arch.System;
using Arch.SystemGroups;
using DCL.AvatarRendering.AvatarShape.UnityInterface;
using DCL.Friends.UserBlocking;
using DCL.Profiles;
using DCL.SceneBannedUsers;
using DCL.VoiceChat.Nearby.Audio;
using ECS.Abstract;
using ECS.LifeCycle.Components;
using LiveKit.Rooms.Streaming;
using LiveKit.Rooms.Streaming.Audio;
using RichTypes;
namespace DCL.VoiceChat.Nearby.Systems
{
/// <summary>
/// Owns the creation part of the Nearby audio-source lifecycle.
/// Creates audio source component for every avatar streamer in audible range
/// the system materializes the audio-source component for the resolver-picked <c>(walletId, CurrentSid)</c> pair when one does not yet exist.
/// </summary>
[UpdateInGroup(typeof(NearbyVoiceChatGroup))]
[UpdateAfter(typeof(NearbyAudibleRangeSystem))]
[UpdateBefore(typeof(NearbyAudioPositionSystem))]
public partial class NearbyAudioBindingSystem : BaseUnityLoopSystem
{
private readonly INearbyAudioStreamRegistry registry;
private readonly IUserBlockingCache userBlockingCache;
private readonly NearbyVoiceChatStateModel stateModel;
private readonly INearbyAudioSourceFactory sourceFactory;
private readonly RoomMetadataCurrentScene roomMetadataCurrentScene;
internal NearbyAudioBindingSystem(World world, INearbyAudioStreamRegistry registry, IUserBlockingCache userBlockingCache, NearbyVoiceChatStateModel stateModel, INearbyAudioSourceFactory sourceFactory, RoomMetadataCurrentScene roomMetadataCurrentScene) : base(world)
{
this.registry = registry;
this.userBlockingCache = userBlockingCache;
this.stateModel = stateModel;
this.sourceFactory = sourceFactory;
this.roomMetadataCurrentScene = roomMetadataCurrentScene;
}
protected override void OnDispose()
{
sourceFactory.DisposeRoot();
}
protected override void Update(float t)
{
// Listening gate: skip the entire avatar query when nearby chat is SUPPRESSED or DISABLED.
// Cleanup system handles the symmetric teardown of any already-bound entities.
if (stateModel.IsListeningDisabled) return;
CreateAndBindAudioSourcesToStreamersQuery(World);
}
[Query]
[None(typeof(NearbyAudioSourceComponent), typeof(DeleteEntityIntention))]
[All(typeof(AvatarBase), typeof(InAudibleRangeTag))]
private void CreateAndBindAudioSourcesToStreamers(Entity avatarEntity, in Profile profile, in NearbyAudioStreamerComponent nearby)
{
string walletId = profile.UserId;
if (string.IsNullOrEmpty(walletId)) return;
// Skip blocked / scene-banned identities. Cleanup system handles already-bound entities; this filter prevents creation in the first place.
if (userBlockingCache.UserIsBlocked(walletId) || roomMetadataCurrentScene.IsUserBanned(walletId)) return;
var key = new StreamKey(walletId, nearby.CurrentSid);
Weak<AudioStream> stream = registry.GetActiveStream(key);
if (stream.Resource.Has)
{
LivekitAudioSource source = sourceFactory.Create(key, stream);
World.Add(avatarEntity, new NearbyAudioSourceComponent(key, source));
}
}
}
}