com.adrenak.univoice 4.6.0 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/Runtime/Impl/Networks/FakeNetwork.cs +6 -0
- package/Runtime/Impl/Networks/FakeNetwork.cs.meta +11 -0
- package/Runtime/Impl/Networks/Mirror/MirrorClient.cs +4 -0
- package/Runtime/Impl/Networks/Mirror/MirrorServer.cs +47 -16
- package/Runtime/Types/VoiceSettings.cs +20 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,16 @@ UniVoice is a voice chat/VoIP solution for Unity.
|
|
|
4
4
|
Some features of UniVoice:
|
|
5
5
|
- 👥 Group voice chat. Multiple peers can join a chatroom and exchange audio.
|
|
6
6
|
|
|
7
|
-
- ⚙
|
|
7
|
+
- ⚙ Fine control over audio data flow.
|
|
8
|
+
* Don't want to listen to a peer? Mute them. Don't want someone listening to you? Deafen them.
|
|
9
|
+
* Group players using tags and control audio flow between them. For example:
|
|
10
|
+
- "red", "blue" and "spectator" tags for two teams playing against each other.
|
|
11
|
+
- Red and Blue teams can only hear each other
|
|
12
|
+
- Spectators can hear everyone
|
|
13
|
+
- clients with "contestant", "judge" and "audience" tags for a virtual talent show.
|
|
14
|
+
- Contestant can be heard by everyone, but don't hear anyone else (for focus)
|
|
15
|
+
- Judges can talk to and hear each other for discussions. They can hear the contestant. But not the audience (for less noise)
|
|
16
|
+
- Audience can hear and talk to each other. They can hear the performer. But they cannot hear the judges.
|
|
8
17
|
|
|
9
18
|
- 🎨 Customize your audio input, output and networking layers.
|
|
10
19
|
* 🌐 __Configurable Network__:
|
|
@@ -171,6 +171,10 @@ namespace Adrenak.UniVoice.Networks {
|
|
|
171
171
|
writer.WriteIntArray(YourVoiceSettings.mutedPeers.ToArray());
|
|
172
172
|
writer.WriteInt(YourVoiceSettings.deafenAll ? 1 : 0);
|
|
173
173
|
writer.WriteIntArray(YourVoiceSettings.deafenedPeers.ToArray());
|
|
174
|
+
writer.WriteString(string.Join(",", YourVoiceSettings.myTags));
|
|
175
|
+
writer.WriteString(string.Join(",", YourVoiceSettings.mutedTags));
|
|
176
|
+
writer.WriteString(string.Join(",", YourVoiceSettings.deafenedTags));
|
|
177
|
+
|
|
174
178
|
var message = new MirrorMessage {
|
|
175
179
|
data = writer.Bytes
|
|
176
180
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// Notes:
|
|
2
2
|
// In Mirror 89.11.0, the OnServerConnectedWithAddress event was added
|
|
3
3
|
// https://github.com/MirrorNetworking/Mirror/releases/tag/v89.11.0
|
|
4
4
|
// OnServerConnected no longer seems to work?
|
|
@@ -106,37 +106,61 @@ namespace Adrenak.UniVoice.Networks {
|
|
|
106
106
|
var reader = new BytesReader(message.data);
|
|
107
107
|
var tag = reader.ReadString();
|
|
108
108
|
|
|
109
|
+
// Server forwards the received audio from a client to other clients based on voice settings.
|
|
110
|
+
// Client can mute or deafen each other using IDs as well as tags
|
|
109
111
|
if (tag.Equals(MirrorMessageTags.AUDIO_FRAME)) {
|
|
110
112
|
// We start with all the peers except the one that's
|
|
111
113
|
// sent the audio
|
|
112
114
|
var peersToForwardAudioTo = ClientIDs
|
|
113
115
|
.Where(x => x != clientId);
|
|
114
116
|
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
+
// Check the voice settings of the sender and eliminate any peers the sender
|
|
118
|
+
// may have deafened
|
|
117
119
|
if (ClientVoiceSettings.TryGetValue(clientId, out var senderSettings)) {
|
|
118
|
-
// If the client sending the audio has deafened everyone
|
|
119
|
-
//
|
|
120
|
+
// If the client sending the audio has deafened everyone,
|
|
121
|
+
// we simply return. Sender's audio should not be forwarded to anyone.
|
|
120
122
|
if (senderSettings.deafenAll)
|
|
121
123
|
return;
|
|
122
124
|
|
|
123
|
-
//
|
|
124
|
-
// deafened
|
|
125
|
+
// Filter the recipient list by removing all peers that the sender has
|
|
126
|
+
// deafened using ID
|
|
125
127
|
peersToForwardAudioTo = peersToForwardAudioTo
|
|
126
128
|
.Where(x => !senderSettings.deafenedPeers.Contains(x));
|
|
129
|
+
|
|
130
|
+
// Further filter the recipient list by removing peers that the sender has
|
|
131
|
+
// deafened using tags
|
|
132
|
+
peersToForwardAudioTo = peersToForwardAudioTo.Where(peer => {
|
|
133
|
+
// Get the voice settings of the peer
|
|
134
|
+
if (ClientVoiceSettings.TryGetValue(peer, out VoiceSettings peerVoiceSettings)) {
|
|
135
|
+
// Check if sender has not deafened peer using tag
|
|
136
|
+
var hasDeafenedPeer = senderSettings.deafenedTags.Intersect(peerVoiceSettings.myTags).Count() > 0;
|
|
137
|
+
return !hasDeafenedPeer;
|
|
138
|
+
}
|
|
139
|
+
// If peer doesn't have voice settings, we can keep the peer in the list
|
|
140
|
+
else {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
127
144
|
}
|
|
128
145
|
|
|
129
|
-
// We iterate through each recipient peer that the sender wants to send
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (ClientVoiceSettings.TryGetValue(
|
|
134
|
-
|
|
146
|
+
// We iterate through each recipient peer that the sender wants to send audio to, checking if
|
|
147
|
+
// they have muted the sender, before forwarding the audio to them.
|
|
148
|
+
foreach (var recipient in peersToForwardAudioTo) {
|
|
149
|
+
// Get the settings of a potential recipient
|
|
150
|
+
if (ClientVoiceSettings.TryGetValue(recipient, out var recipientSettings)) {
|
|
151
|
+
// If a peer has muted everyone, don't send audio
|
|
152
|
+
if (recipientSettings.muteAll)
|
|
135
153
|
continue;
|
|
136
|
-
|
|
154
|
+
|
|
155
|
+
// If the peers has muted the sender using ID, skip sending audio
|
|
156
|
+
if (recipientSettings.mutedPeers.Contains(clientId))
|
|
157
|
+
continue;
|
|
158
|
+
|
|
159
|
+
// If the peer has muted the sender using tag, skip sending audio
|
|
160
|
+
if (recipientSettings.mutedTags.Intersect(senderSettings.myTags).Count() > 0)
|
|
137
161
|
continue;
|
|
138
162
|
}
|
|
139
|
-
SendToClient(
|
|
163
|
+
SendToClient(recipient, message.data, Channels.Unreliable);
|
|
140
164
|
}
|
|
141
165
|
}
|
|
142
166
|
else if (tag.Equals(MirrorMessageTags.VOICE_SETTINGS)) {
|
|
@@ -147,11 +171,18 @@ namespace Adrenak.UniVoice.Networks {
|
|
|
147
171
|
var mutedPeers = reader.ReadIntArray().ToList();
|
|
148
172
|
var deafenAll = reader.ReadInt() == 1 ? true : false;
|
|
149
173
|
var deafenedPeers = reader.ReadIntArray().ToList();
|
|
174
|
+
var myTags = reader.ReadString().Split(",").ToList();
|
|
175
|
+
var mutedTags = reader.ReadString().Split(",").ToList();
|
|
176
|
+
var deafenedTags = reader.ReadString().Split(",").ToList();
|
|
177
|
+
|
|
150
178
|
var voiceSettings = new VoiceSettings {
|
|
151
179
|
muteAll = muteAll,
|
|
152
180
|
mutedPeers = mutedPeers,
|
|
153
181
|
deafenAll = deafenAll,
|
|
154
|
-
deafenedPeers = deafenedPeers
|
|
182
|
+
deafenedPeers = deafenedPeers,
|
|
183
|
+
myTags = myTags,
|
|
184
|
+
mutedTags = mutedTags,
|
|
185
|
+
deafenedTags = deafenedTags
|
|
155
186
|
};
|
|
156
187
|
if (ClientVoiceSettings.ContainsKey(clientId))
|
|
157
188
|
ClientVoiceSettings[clientId] = voiceSettings;
|
|
@@ -22,6 +22,26 @@ namespace Adrenak.UniVoice {
|
|
|
22
22
|
/// </summary>
|
|
23
23
|
public List<int> deafenedPeers = new List<int>();
|
|
24
24
|
|
|
25
|
+
/// <summary>
|
|
26
|
+
/// The tags associated with this client.
|
|
27
|
+
/// DO NOT USE COMMAS (,)
|
|
28
|
+
/// </summary>
|
|
29
|
+
public List<string> myTags = new List<string>();
|
|
30
|
+
|
|
31
|
+
/// <summary>
|
|
32
|
+
/// The tags, which if associated with a peer, would cause
|
|
33
|
+
/// those the audio of that peer to not be send to this peer
|
|
34
|
+
/// DO NOT USE COMMAS (,)
|
|
35
|
+
/// </summary>
|
|
36
|
+
public List<string> mutedTags = new List<string>();
|
|
37
|
+
|
|
38
|
+
/// <summary>
|
|
39
|
+
/// The tags, which if associated with a peer, would cause
|
|
40
|
+
/// those peers to not receive audio from this client
|
|
41
|
+
/// DO NOT USE COMMAS (,)
|
|
42
|
+
/// </summary>
|
|
43
|
+
public List<string> deafenedTags = new List<string>();
|
|
44
|
+
|
|
25
45
|
/// <summary>
|
|
26
46
|
/// Sets the deaf status of a peer
|
|
27
47
|
/// </summary>
|