com.adrenak.univoice 1.2.1 → 2.0.1
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/CHANGELOG.md +12 -0
- package/Runtime/ChatroomAgent.cs +21 -35
- package/Runtime/Interfaces/IAudioInput.cs +4 -2
- package/Runtime/Interfaces/IAudioOutput.cs +2 -0
- package/Runtime/Interfaces/IChatroomNetwork.cs +6 -4
- package/Runtime/Types/ChatroomAgentMode.cs +1 -0
- package/Runtime/Types/ChatroomAudioSegment.cs +0 -5
- package/Runtime/Types/ChatroomPeerSettings.cs +1 -0
- package/package.json +20 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
# [1.2.0](https://github.com/adrenak/univoice/compare/v1.1.4...v1.2.0) (2022-09-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Update README.md ([5c234ee](https://github.com/adrenak/univoice/commit/5c234ee1e6aad430f72b4879a401bb98f3e68b88))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Remove inbuilt implementations. Remove samples. ([dbfc4c0](https://github.com/adrenak/univoice/commit/dbfc4c0a1ffd99d03aefe72aec0e27debe68525a))
|
|
12
|
+
|
|
1
13
|
## [1.1.4](https://github.com/adrenak/univoice/compare/v1.1.3...v1.1.4) (2021-08-10)
|
|
2
14
|
|
|
3
15
|
|
package/Runtime/ChatroomAgent.cs
CHANGED
|
@@ -140,47 +140,40 @@ namespace Adrenak.UniVoice {
|
|
|
140
140
|
// Node client events
|
|
141
141
|
Network.OnJoinedChatroom += id => {
|
|
142
142
|
CurrentMode = ChatroomAgentMode.Guest;
|
|
143
|
-
EnsurePeerSettings(0);
|
|
144
143
|
};
|
|
145
144
|
Network.OnLeftChatroom += () =>
|
|
146
145
|
RemoveAllPeers();
|
|
147
|
-
Network.OnPeerJoinedChatroom += id =>
|
|
148
|
-
|
|
146
|
+
Network.OnPeerJoinedChatroom += id =>
|
|
147
|
+
AddPeer(id);
|
|
149
148
|
Network.OnPeerLeftChatroom += id =>
|
|
150
149
|
RemovePeer(id);
|
|
151
150
|
|
|
152
151
|
// Stream the incoming audio data using the right peer output
|
|
153
|
-
Network.OnAudioReceived += data => {
|
|
152
|
+
Network.OnAudioReceived += (peerID, data) => {
|
|
154
153
|
// if we're muting all, no point continuing.
|
|
155
154
|
if (MuteOthers) return;
|
|
156
155
|
|
|
157
|
-
var id = data.id;
|
|
158
156
|
var index = data.segmentIndex;
|
|
159
157
|
var frequency = data.frequency;
|
|
160
158
|
var channels = data.channelCount;
|
|
161
159
|
var samples = data.samples;
|
|
162
160
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (HasSettingsForPeer(id) && !PeerSettings[id].muteThem)
|
|
166
|
-
PeerOutputs[id].Feed(index, frequency, channels, samples);
|
|
161
|
+
if (HasSettingsForPeer(peerID) && !PeerSettings[peerID].muteThem)
|
|
162
|
+
PeerOutputs[peerID].Feed(index, frequency, channels, samples);
|
|
167
163
|
};
|
|
168
164
|
|
|
169
|
-
|
|
170
165
|
AudioInput.OnSegmentReady += (index, samples) => {
|
|
171
166
|
if (MuteSelf) return;
|
|
172
167
|
|
|
173
168
|
// Get all the recipients we haven't muted ourselves to
|
|
174
169
|
var recipients = Network.PeerIDs
|
|
175
170
|
.Where(x => {
|
|
176
|
-
return HasSettingsForPeer(x)
|
|
177
|
-
&& !PeerSettings[x].muteSelf;
|
|
171
|
+
return HasSettingsForPeer(x) && !PeerSettings[x].muteSelf;
|
|
178
172
|
});
|
|
179
173
|
|
|
180
174
|
// Send the audio segment to every deserving recipient
|
|
181
175
|
foreach (var recipient in recipients)
|
|
182
|
-
Network.SendAudioSegment(new ChatroomAudioSegment {
|
|
183
|
-
id = recipient,
|
|
176
|
+
Network.SendAudioSegment(recipient, new ChatroomAudioSegment {
|
|
184
177
|
segmentIndex = index,
|
|
185
178
|
frequency = AudioInput.Frequency,
|
|
186
179
|
channelCount = AudioInput.ChannelCount,
|
|
@@ -189,11 +182,24 @@ namespace Adrenak.UniVoice {
|
|
|
189
182
|
};
|
|
190
183
|
}
|
|
191
184
|
|
|
185
|
+
void AddPeer(short id) {
|
|
186
|
+
if (!PeerSettings.ContainsKey(id))
|
|
187
|
+
PeerSettings.Add(id, new ChatroomPeerSettings());
|
|
188
|
+
if(!PeerOutputs.ContainsKey(id)) {
|
|
189
|
+
var output = AudioOutputFactory.Create(
|
|
190
|
+
AudioInput.Frequency,
|
|
191
|
+
AudioInput.ChannelCount,
|
|
192
|
+
AudioInput.Frequency * AudioInput.ChannelCount / AudioInput.SegmentRate
|
|
193
|
+
);
|
|
194
|
+
output.ID = id.ToString();
|
|
195
|
+
PeerOutputs.Add(id, output);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
192
199
|
void RemovePeer(short id) {
|
|
193
200
|
if (PeerSettings.ContainsKey(id))
|
|
194
201
|
PeerSettings.Remove(id);
|
|
195
202
|
if (PeerOutputs.ContainsKey(id)) {
|
|
196
|
-
PeerOutputs[id].Dispose();
|
|
197
203
|
PeerOutputs[id].Dispose();
|
|
198
204
|
PeerOutputs.Remove(id);
|
|
199
205
|
}
|
|
@@ -202,27 +208,7 @@ namespace Adrenak.UniVoice {
|
|
|
202
208
|
void RemoveAllPeers() =>
|
|
203
209
|
PeerSettings.Keys.ToList().ForEach(x => RemovePeer(x));
|
|
204
210
|
|
|
205
|
-
void EnsurePeerSettings(short id) =>
|
|
206
|
-
PeerSettings.EnsureKey(id, new ChatroomPeerSettings());
|
|
207
|
-
|
|
208
211
|
bool HasSettingsForPeer(short id) => PeerSettings.ContainsKey(id);
|
|
209
|
-
|
|
210
|
-
void EnsurePeerStreamer(
|
|
211
|
-
short id,
|
|
212
|
-
int frequency,
|
|
213
|
-
int channels,
|
|
214
|
-
int segmentLength
|
|
215
|
-
) {
|
|
216
|
-
if (!PeerOutputs.ContainsKey(id) && PeerSettings.ContainsKey(id)) {
|
|
217
|
-
var output = AudioOutputFactory.Create(
|
|
218
|
-
frequency,
|
|
219
|
-
channels,
|
|
220
|
-
segmentLength
|
|
221
|
-
);
|
|
222
|
-
output.ID = id.ToString();
|
|
223
|
-
PeerOutputs.Add(id, output);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
212
|
#endregion
|
|
227
213
|
}
|
|
228
214
|
}
|
|
@@ -26,8 +26,10 @@ namespace Adrenak.UniVoice {
|
|
|
26
26
|
/// <summary>
|
|
27
27
|
/// The number of segments (a segment is a sequence of audio samples)
|
|
28
28
|
/// that are emitted from the source every second.
|
|
29
|
-
/// A 16000 Hz source with a rate of 10
|
|
30
|
-
/// 1600 samples every 100 milliseconds.
|
|
29
|
+
/// A 16000 Hz source with one channel at a rate of 10
|
|
30
|
+
/// will output an array of 1600 samples every 100 milliseconds.
|
|
31
|
+
/// A 44000 Hz source with two channels at a rate of 10
|
|
32
|
+
/// will output an array of 8800 samples every 100 milliseconds.
|
|
31
33
|
/// </summary>
|
|
32
34
|
int SegmentRate { get; }
|
|
33
35
|
}
|
|
@@ -10,6 +10,8 @@ namespace Adrenak.UniVoice {
|
|
|
10
10
|
/// destination doesn't matter.
|
|
11
11
|
/// </summary>
|
|
12
12
|
public interface IAudioOutput : IDisposable {
|
|
13
|
+
// TODO: Maybe introduce a PeerID property?
|
|
14
|
+
|
|
13
15
|
/// <summary>
|
|
14
16
|
/// An ID associated with this audio output
|
|
15
17
|
/// </summary>
|
|
@@ -20,7 +20,7 @@ namespace Adrenak.UniVoice {
|
|
|
20
20
|
/// Provides an exception as event data.
|
|
21
21
|
/// </summary>
|
|
22
22
|
event Action<Exception> OnChatroomCreationFailed;
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
/// <summary>
|
|
25
25
|
/// Fired when a chatroom is closed.
|
|
26
26
|
/// </summary>
|
|
@@ -46,6 +46,8 @@ namespace Adrenak.UniVoice {
|
|
|
46
46
|
/// <summary>
|
|
47
47
|
/// Fired when a peer joins the chatroom.
|
|
48
48
|
/// Provides the ID of the peer as event data.
|
|
49
|
+
/// This action also MUST be called for all previously
|
|
50
|
+
/// existing peers when we connect to a network.
|
|
49
51
|
/// </summary>
|
|
50
52
|
event Action<short> OnPeerJoinedChatroom;
|
|
51
53
|
|
|
@@ -58,12 +60,12 @@ namespace Adrenak.UniVoice {
|
|
|
58
60
|
/// <summary>
|
|
59
61
|
/// Fired when the network receives audio data from a peer.
|
|
60
62
|
/// </summary>
|
|
61
|
-
event Action<ChatroomAudioSegment> OnAudioReceived;
|
|
63
|
+
event Action<short, ChatroomAudioSegment> OnAudioReceived;
|
|
62
64
|
|
|
63
65
|
/// <summary>
|
|
64
66
|
/// Fired when the local user sets audio data to a peer.
|
|
65
67
|
/// </summary>
|
|
66
|
-
event Action<ChatroomAudioSegment> OnAudioSent;
|
|
68
|
+
event Action<short, ChatroomAudioSegment> OnAudioSent;
|
|
67
69
|
#endregion
|
|
68
70
|
|
|
69
71
|
// ====================================================================
|
|
@@ -111,7 +113,7 @@ namespace Adrenak.UniVoice {
|
|
|
111
113
|
/// Sends audio data over the network
|
|
112
114
|
/// </summary>
|
|
113
115
|
/// <param name="data">The data to be transmitted.</param>
|
|
114
|
-
void SendAudioSegment(ChatroomAudioSegment data);
|
|
116
|
+
void SendAudioSegment(short peerID, ChatroomAudioSegment data);
|
|
115
117
|
#endregion
|
|
116
118
|
}
|
|
117
119
|
}
|
|
@@ -4,11 +4,6 @@
|
|
|
4
4
|
/// A data structure representing the audio transmitted over the network.
|
|
5
5
|
/// </summary>
|
|
6
6
|
public struct ChatroomAudioSegment {
|
|
7
|
-
/// <summary>
|
|
8
|
-
/// ID of the peer that has sent the data
|
|
9
|
-
/// </summary>
|
|
10
|
-
public short id;
|
|
11
|
-
|
|
12
7
|
/// <summary>
|
|
13
8
|
/// The segment index of the audio samples
|
|
14
9
|
/// </summary>
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "com.adrenak.univoice",
|
|
3
|
-
"version": "
|
|
4
|
-
"displayName": "Adrenak.UniVoice",
|
|
5
|
-
"description": "Voice chat/VoIP solution for Unity.",
|
|
6
|
-
"unity": "2019.4",
|
|
7
|
-
"author": "Vatsal Ambastha <ambastha.vatsal@gmail.com> (http://www.vatsalambastha.com)",
|
|
8
|
-
"license": "MIT",
|
|
9
|
-
"keywords": [
|
|
10
|
-
"Peer To Peer",
|
|
11
|
-
"WebRTC",
|
|
12
|
-
"P2P",
|
|
13
|
-
"Networking",
|
|
14
|
-
"Voice Chat",
|
|
15
|
-
"voip"
|
|
16
|
-
],
|
|
17
|
-
"publishConfig": {
|
|
18
|
-
"registry": "https://registry.npmjs.org"
|
|
19
|
-
}
|
|
20
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "com.adrenak.univoice",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"displayName": "Adrenak.UniVoice",
|
|
5
|
+
"description": "Voice chat/VoIP solution for Unity.",
|
|
6
|
+
"unity": "2019.4",
|
|
7
|
+
"author": "Vatsal Ambastha <ambastha.vatsal@gmail.com> (http://www.vatsalambastha.com)",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"Peer To Peer",
|
|
11
|
+
"WebRTC",
|
|
12
|
+
"P2P",
|
|
13
|
+
"Networking",
|
|
14
|
+
"Voice Chat",
|
|
15
|
+
"voip"
|
|
16
|
+
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"registry": "https://registry.npmjs.org"
|
|
19
|
+
}
|
|
20
|
+
}
|