com.adrenak.univoice 2.0.0 → 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 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
 
@@ -140,12 +140,11 @@ 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
- EnsurePeerSettings(id);
146
+ Network.OnPeerJoinedChatroom += id =>
147
+ AddPeer(id);
149
148
  Network.OnPeerLeftChatroom += id =>
150
149
  RemovePeer(id);
151
150
 
@@ -159,8 +158,6 @@ namespace Adrenak.UniVoice {
159
158
  var channels = data.channelCount;
160
159
  var samples = data.samples;
161
160
 
162
- EnsurePeerStreamer(peerID, frequency, channels, samples.Length);
163
-
164
161
  if (HasSettingsForPeer(peerID) && !PeerSettings[peerID].muteThem)
165
162
  PeerOutputs[peerID].Feed(index, frequency, channels, samples);
166
163
  };
@@ -171,8 +168,7 @@ namespace Adrenak.UniVoice {
171
168
  // Get all the recipients we haven't muted ourselves to
172
169
  var recipients = Network.PeerIDs
173
170
  .Where(x => {
174
- return HasSettingsForPeer(x)
175
- && !PeerSettings[x].muteSelf;
171
+ return HasSettingsForPeer(x) && !PeerSettings[x].muteSelf;
176
172
  });
177
173
 
178
174
  // Send the audio segment to every deserving recipient
@@ -186,11 +182,24 @@ namespace Adrenak.UniVoice {
186
182
  };
187
183
  }
188
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
+
189
199
  void RemovePeer(short id) {
190
200
  if (PeerSettings.ContainsKey(id))
191
201
  PeerSettings.Remove(id);
192
202
  if (PeerOutputs.ContainsKey(id)) {
193
- PeerOutputs[id].Dispose();
194
203
  PeerOutputs[id].Dispose();
195
204
  PeerOutputs.Remove(id);
196
205
  }
@@ -199,27 +208,7 @@ namespace Adrenak.UniVoice {
199
208
  void RemoveAllPeers() =>
200
209
  PeerSettings.Keys.ToList().ForEach(x => RemovePeer(x));
201
210
 
202
- void EnsurePeerSettings(short id) =>
203
- PeerSettings.EnsureKey(id, new ChatroomPeerSettings());
204
-
205
211
  bool HasSettingsForPeer(short id) => PeerSettings.ContainsKey(id);
206
-
207
- void EnsurePeerStreamer(
208
- short id,
209
- int frequency,
210
- int channels,
211
- int segmentLength
212
- ) {
213
- if (!PeerOutputs.ContainsKey(id) && PeerSettings.ContainsKey(id)) {
214
- var output = AudioOutputFactory.Create(
215
- frequency,
216
- channels,
217
- segmentLength
218
- );
219
- output.ID = id.ToString();
220
- PeerOutputs.Add(id, output);
221
- }
222
- }
223
212
  #endregion
224
213
  }
225
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 will output an array of
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>
@@ -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
 
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
- {
2
- "name": "com.adrenak.univoice",
3
- "version": "2.0.0",
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
+ }