com.adrenak.univoice 2.0.2 → 4.0.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/LICENSE +21 -21
- package/LICENSE.meta +7 -7
- package/README.md +32 -54
- package/README.md.meta +7 -7
- package/Runtime/Adrenak.UniVoice.Runtime.asmdef +19 -3
- package/Runtime/Adrenak.UniVoice.Runtime.asmdef.meta +7 -7
- package/Runtime/ClientSession.cs +137 -0
- package/Runtime/{Types/ChatroomAgentMode.cs.meta → ClientSession.cs.meta} +11 -11
- package/Runtime/Common/Utils.cs +55 -0
- package/Runtime/{Interfaces/IChatroomNetwork.cs.meta → Common/Utils.cs.meta} +11 -11
- package/Runtime/Common.meta +8 -0
- package/Runtime/Impl/Filters/GaussianAudioBlur.cs +90 -0
- package/Runtime/{ChatroomAgent.cs.meta → Impl/Filters/GaussianAudioBlur.cs.meta} +11 -11
- package/Runtime/Impl/Filters/OpusFilter.cs +85 -0
- package/Runtime/Impl/Filters/OpusFilter.cs.meta +11 -0
- package/Runtime/Impl/Filters.meta +8 -0
- package/Runtime/Impl/Inputs/UniMicInput.cs +39 -0
- package/Runtime/Impl/Inputs/UniMicInput.cs.meta +11 -0
- package/Runtime/Impl/Inputs.meta +8 -0
- package/Runtime/Impl/Networks/Mirror/MirrorClient.cs +161 -0
- package/Runtime/Impl/Networks/Mirror/MirrorClient.cs.meta +11 -0
- package/Runtime/Impl/Networks/Mirror/MirrorMessage.cs +21 -0
- package/Runtime/Impl/Networks/Mirror/MirrorMessage.cs.meta +11 -0
- package/Runtime/Impl/Networks/Mirror/MirrorMessageTags.cs +16 -0
- package/Runtime/Impl/Networks/Mirror/MirrorMessageTags.cs.meta +11 -0
- package/Runtime/Impl/Networks/Mirror/MirrorModeObserver.cs +43 -0
- package/Runtime/Impl/Networks/Mirror/MirrorModeObserver.cs.meta +11 -0
- package/Runtime/Impl/Networks/Mirror/MirrorServer.cs +234 -0
- package/Runtime/Impl/Networks/Mirror/MirrorServer.cs.meta +11 -0
- package/Runtime/Impl/Networks/Mirror.meta +8 -0
- package/Runtime/Impl/Networks.meta +8 -0
- package/Runtime/Impl/Outputs/StreamedAudioSourceOutput.cs +56 -0
- package/Runtime/Impl/Outputs/StreamedAudioSourceOutput.cs.meta +11 -0
- package/Runtime/Impl/Outputs.meta +8 -0
- package/Runtime/Impl.meta +8 -0
- package/Runtime/Interfaces/IAudioClient.cs +77 -0
- package/Runtime/Interfaces/IAudioClient.cs.meta +11 -0
- package/Runtime/Interfaces/IAudioFilter.cs +10 -0
- package/Runtime/Interfaces/IAudioFilter.cs.meta +11 -0
- package/Runtime/Interfaces/IAudioInput.cs +1 -24
- package/Runtime/Interfaces/IAudioInput.cs.meta +11 -11
- package/Runtime/Interfaces/IAudioOutput.cs +6 -30
- package/Runtime/Interfaces/IAudioOutput.cs.meta +11 -11
- package/Runtime/Interfaces/IAudioOutputFactory.cs +2 -7
- package/Runtime/Interfaces/IAudioOutputFactory.cs.meta +11 -11
- package/Runtime/Interfaces/IAudioServer.cs +41 -0
- package/Runtime/Interfaces/IAudioServer.cs.meta +11 -0
- package/Runtime/Interfaces.meta +8 -8
- package/Runtime/Types/{ChatroomAudioSegment.cs → AudioFrame.cs} +27 -26
- package/Runtime/Types/{ChatroomAudioSegment.cs.meta → AudioFrame.cs.meta} +11 -11
- package/Runtime/Types/VoiceSettings.cs +53 -0
- package/Runtime/Types/VoiceSettings.cs.meta +11 -0
- package/Runtime/Types.meta +8 -8
- package/Runtime.meta +9 -9
- package/Samples~/Group Chat Sample/Prefabs/Mic Toggle.prefab +235 -0
- package/{CHANGELOG.md.meta → Samples~/Group Chat Sample/Prefabs/Mic Toggle.prefab.meta } +7 -7
- package/Samples~/Group Chat Sample/Prefabs/Peer View.prefab +851 -0
- package/Samples~/Group Chat Sample/Prefabs/Peer View.prefab.meta +7 -0
- package/Samples~/Group Chat Sample/Prefabs.meta +8 -0
- package/Samples~/Group Chat Sample/Scenes/GroupVoiceCallSample-Mirror.unity +2160 -0
- package/Samples~/Group Chat Sample/Scenes/GroupVoiceCallSample-Mirror.unity.meta +7 -0
- package/Samples~/Group Chat Sample/Scenes.meta +8 -0
- package/Samples~/Group Chat Sample/Scripts/GroupVoiceCallMirrorSample.cs +217 -0
- package/Samples~/Group Chat Sample/Scripts/GroupVoiceCallMirrorSample.cs.meta +11 -0
- package/Samples~/Group Chat Sample/Scripts/PeerView.cs +74 -0
- package/Samples~/Group Chat Sample/Scripts/PeerView.cs.meta +11 -0
- package/Samples~/Group Chat Sample/Scripts.meta +8 -0
- package/Samples~/Group Chat Sample/Sprites/mic.png +0 -0
- package/Samples~/Group Chat Sample/Sprites/mic.png.meta +88 -0
- package/Samples~/Group Chat Sample/Sprites/off.png +0 -0
- package/Samples~/Group Chat Sample/Sprites/off.png.meta +88 -0
- package/Samples~/Group Chat Sample/Sprites/on.png +0 -0
- package/Samples~/Group Chat Sample/Sprites/on.png.meta +88 -0
- package/Samples~/Group Chat Sample/Sprites/speaker.png +0 -0
- package/Samples~/Group Chat Sample/Sprites/speaker.png.meta +88 -0
- package/Samples~/Group Chat Sample/Sprites.meta +8 -0
- package/Samples~/Group Chat Sample.meta +8 -0
- package/package.json +39 -20
- package/package.json.meta +7 -7
- package/CHANGELOG.md +0 -67
- package/Runtime/ChatroomAgent.cs +0 -215
- package/Runtime/Extensions.cs +0 -39
- package/Runtime/Extensions.cs.meta +0 -12
- package/Runtime/Interfaces/IChatroomNetwork.cs +0 -121
- package/Runtime/Types/ChatroomAgentMode.cs +0 -22
- package/Runtime/Types/ChatroomPeerSettings.cs +0 -18
- package/Runtime/Types/ChatroomPeerSettings.cs.meta +0 -11
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: f614e31fdd0562a4ebb9b6c2126ebf8a
|
|
3
|
+
TextureImporter:
|
|
4
|
+
fileIDToRecycleName: {}
|
|
5
|
+
externalObjects: {}
|
|
6
|
+
serializedVersion: 9
|
|
7
|
+
mipmaps:
|
|
8
|
+
mipMapMode: 0
|
|
9
|
+
enableMipMap: 0
|
|
10
|
+
sRGBTexture: 1
|
|
11
|
+
linearTexture: 0
|
|
12
|
+
fadeOut: 0
|
|
13
|
+
borderMipMap: 0
|
|
14
|
+
mipMapsPreserveCoverage: 0
|
|
15
|
+
alphaTestReferenceValue: 0.5
|
|
16
|
+
mipMapFadeDistanceStart: 1
|
|
17
|
+
mipMapFadeDistanceEnd: 3
|
|
18
|
+
bumpmap:
|
|
19
|
+
convertToNormalMap: 0
|
|
20
|
+
externalNormalMap: 0
|
|
21
|
+
heightScale: 0.25
|
|
22
|
+
normalMapFilter: 0
|
|
23
|
+
isReadable: 0
|
|
24
|
+
streamingMipmaps: 0
|
|
25
|
+
streamingMipmapsPriority: 0
|
|
26
|
+
grayScaleToAlpha: 0
|
|
27
|
+
generateCubemap: 6
|
|
28
|
+
cubemapConvolution: 0
|
|
29
|
+
seamlessCubemap: 0
|
|
30
|
+
textureFormat: 1
|
|
31
|
+
maxTextureSize: 2048
|
|
32
|
+
textureSettings:
|
|
33
|
+
serializedVersion: 2
|
|
34
|
+
filterMode: -1
|
|
35
|
+
aniso: -1
|
|
36
|
+
mipBias: -100
|
|
37
|
+
wrapU: 1
|
|
38
|
+
wrapV: 1
|
|
39
|
+
wrapW: -1
|
|
40
|
+
nPOTScale: 0
|
|
41
|
+
lightmap: 0
|
|
42
|
+
compressionQuality: 50
|
|
43
|
+
spriteMode: 1
|
|
44
|
+
spriteExtrude: 1
|
|
45
|
+
spriteMeshType: 1
|
|
46
|
+
alignment: 0
|
|
47
|
+
spritePivot: {x: 0.5, y: 0.5}
|
|
48
|
+
spritePixelsToUnits: 100
|
|
49
|
+
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
|
50
|
+
spriteGenerateFallbackPhysicsShape: 1
|
|
51
|
+
alphaUsage: 1
|
|
52
|
+
alphaIsTransparency: 1
|
|
53
|
+
spriteTessellationDetail: -1
|
|
54
|
+
textureType: 8
|
|
55
|
+
textureShape: 1
|
|
56
|
+
singleChannelComponent: 0
|
|
57
|
+
maxTextureSizeSet: 0
|
|
58
|
+
compressionQualitySet: 0
|
|
59
|
+
textureFormatSet: 0
|
|
60
|
+
platformSettings:
|
|
61
|
+
- serializedVersion: 2
|
|
62
|
+
buildTarget: DefaultTexturePlatform
|
|
63
|
+
maxTextureSize: 256
|
|
64
|
+
resizeAlgorithm: 0
|
|
65
|
+
textureFormat: -1
|
|
66
|
+
textureCompression: 1
|
|
67
|
+
compressionQuality: 50
|
|
68
|
+
crunchedCompression: 0
|
|
69
|
+
allowsAlphaSplitting: 0
|
|
70
|
+
overridden: 0
|
|
71
|
+
androidETC2FallbackOverride: 0
|
|
72
|
+
spriteSheet:
|
|
73
|
+
serializedVersion: 2
|
|
74
|
+
sprites: []
|
|
75
|
+
outline: []
|
|
76
|
+
physicsShape: []
|
|
77
|
+
bones: []
|
|
78
|
+
spriteID: 3622c0ab7514b294e91e1e29cbfae826
|
|
79
|
+
vertices: []
|
|
80
|
+
indices:
|
|
81
|
+
edges: []
|
|
82
|
+
weights: []
|
|
83
|
+
spritePackingTag:
|
|
84
|
+
pSDRemoveMatte: 0
|
|
85
|
+
pSDShowRemoveMatteOption: 0
|
|
86
|
+
userData:
|
|
87
|
+
assetBundleName:
|
|
88
|
+
assetBundleVariant:
|
package/package.json
CHANGED
|
@@ -1,20 +1,39 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "com.adrenak.univoice",
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"displayName": "Adrenak.UniVoice",
|
|
5
|
+
"description": "Network agnostic voice chat/VoIP framework for Unity.",
|
|
6
|
+
"unity": "2019.4",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Vatsal Ambastha",
|
|
9
|
+
"email": "ambastha.vatsal@gmail.com",
|
|
10
|
+
"url": "http://www.vatsalambastha.com"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"Mirror",
|
|
15
|
+
"Networking",
|
|
16
|
+
"Voice Chat",
|
|
17
|
+
"voip",
|
|
18
|
+
"Unity",
|
|
19
|
+
"Unity3d",
|
|
20
|
+
"VR",
|
|
21
|
+
"AR",
|
|
22
|
+
"Metaverse"
|
|
23
|
+
],
|
|
24
|
+
"samples": [
|
|
25
|
+
{
|
|
26
|
+
"displayName": "Samples",
|
|
27
|
+
"description": "UniVoice Samples to get you started",
|
|
28
|
+
"path": "Samples~"
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"registry": "https://registry.npmjs.org"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"com.adrenak.brw": "1.0.1",
|
|
36
|
+
"com.adrenak.unimic": "3.2.1",
|
|
37
|
+
"com.adrenak.unityopus": "1.0.0"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/package.json.meta
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
2
|
-
guid: 5677af848094d404f835a6468b36f003
|
|
3
|
-
TextScriptImporter:
|
|
4
|
-
externalObjects: {}
|
|
5
|
-
userData:
|
|
6
|
-
assetBundleName:
|
|
7
|
-
assetBundleVariant:
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: 5677af848094d404f835a6468b36f003
|
|
3
|
+
TextScriptImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
userData:
|
|
6
|
+
assetBundleName:
|
|
7
|
+
assetBundleVariant:
|
package/CHANGELOG.md
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
## [2.0.2](https://github.com/adrenak/univoice/compare/v2.0.1...v2.0.2) (2022-11-02)
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
### Bug Fixes
|
|
5
|
-
|
|
6
|
-
* remove comment about possible PeerID in IAudioOutput ([2246bb2](https://github.com/adrenak/univoice/commit/2246bb2bef234b84bdf6cd55a9faf87e09133953))
|
|
7
|
-
|
|
8
|
-
## [1.2.1](https://github.com/adrenak/univoice/compare/v1.2.0...v1.2.1) (2022-10-10)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
### Bug Fixes
|
|
12
|
-
|
|
13
|
-
* PeersOutputs gets filled as peers join, not when they start ([42eaeb9](https://github.com/adrenak/univoice/commit/42eaeb95eef4eea7ee559da9fdbcac78ceb941b4))
|
|
14
|
-
|
|
15
|
-
# [1.2.0](https://github.com/adrenak/univoice/compare/v1.1.4...v1.2.0) (2022-09-20)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
### Bug Fixes
|
|
19
|
-
|
|
20
|
-
* Update README.md ([5c234ee](https://github.com/adrenak/univoice/commit/5c234ee1e6aad430f72b4879a401bb98f3e68b88))
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
### Features
|
|
24
|
-
|
|
25
|
-
* Remove inbuilt implementations. Remove samples. ([dbfc4c0](https://github.com/adrenak/univoice/commit/dbfc4c0a1ffd99d03aefe72aec0e27debe68525a))
|
|
26
|
-
|
|
27
|
-
## [1.1.4](https://github.com/adrenak/univoice/compare/v1.1.3...v1.1.4) (2021-08-10)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
### Bug Fixes
|
|
31
|
-
|
|
32
|
-
* Spell-fix in README ([fcbc7c6](https://github.com/adrenak/univoice/commit/fcbc7c6c28c84415a50050d7014ecdfc39347309))
|
|
33
|
-
|
|
34
|
-
## [1.1.3](https://github.com/adrenak/univoice/compare/v1.1.2...v1.1.3) (2021-06-03)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
### Bug Fixes
|
|
38
|
-
|
|
39
|
-
* Add missing mute others toggle in sample scene. ([cff9574](https://github.com/adrenak/univoice/commit/cff9574bdd4b769de519f451e489b9dcdb76f649))
|
|
40
|
-
|
|
41
|
-
## [1.1.2](https://github.com/adrenak/univoice/compare/v1.1.1...v1.1.2) (2021-06-02)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
### Bug Fixes
|
|
45
|
-
|
|
46
|
-
* README fix ([d03db44](https://github.com/adrenak/univoice/commit/d03db449e1fe2557a57df75ccfc8fe4a310f308f))
|
|
47
|
-
|
|
48
|
-
## [1.1.1](https://github.com/adrenak/univoice/compare/v1.1.0...v1.1.1) (2021-06-02)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
### Bug Fixes
|
|
52
|
-
|
|
53
|
-
* Prevent sample app screen from sleeping. ([545d96f](https://github.com/adrenak/univoice/commit/545d96f16b858ba1dbdb01de5298ba62c06c2725))
|
|
54
|
-
|
|
55
|
-
# [1.1.0](https://github.com/adrenak/univoice/compare/v1.0.0...v1.1.0) (2021-06-02)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
### Features
|
|
59
|
-
|
|
60
|
-
* InbuiltAudioOutput now also accepts minimum segment count and ([294bfef](https://github.com/adrenak/univoice/commit/294bfef5677d49cd941b513c421980cf6a5e393f))
|
|
61
|
-
|
|
62
|
-
# 1.0.0 (2021-06-02)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
### Features
|
|
66
|
-
|
|
67
|
-
* Full rebuild with AirPeer 1.2.0 ([9327b2a](https://github.com/adrenak/univoice/commit/9327b2a05da766e91bad5f8e6288e5c328ded429))
|
package/Runtime/ChatroomAgent.cs
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using System.Linq;
|
|
3
|
-
using System.Collections.Generic;
|
|
4
|
-
|
|
5
|
-
namespace Adrenak.UniVoice {
|
|
6
|
-
/// <summary>
|
|
7
|
-
/// Provides the means to host or connect to a chatroom.
|
|
8
|
-
/// </summary>
|
|
9
|
-
public class ChatroomAgent : IDisposable {
|
|
10
|
-
// ====================================================================
|
|
11
|
-
#region PROPERTIES
|
|
12
|
-
// ====================================================================
|
|
13
|
-
/// <summary>
|
|
14
|
-
/// The underlying network which the agent uses to host or connect to
|
|
15
|
-
/// chatrooms, and send and receive data to and from peers
|
|
16
|
-
/// </summary>
|
|
17
|
-
public IChatroomNetwork Network { get; private set; }
|
|
18
|
-
|
|
19
|
-
/// <summary>
|
|
20
|
-
/// Source of outgoing audio that can be
|
|
21
|
-
/// transmitted over the network to peers
|
|
22
|
-
/// </summary>
|
|
23
|
-
public IAudioInput AudioInput { get; private set; }
|
|
24
|
-
|
|
25
|
-
/// <summary>
|
|
26
|
-
/// A factory that returns an <see cref="IAudioOutput"/>
|
|
27
|
-
/// instance. Used every time a Peer connects for that peer to get
|
|
28
|
-
/// an output for that peer.
|
|
29
|
-
/// </summary>
|
|
30
|
-
public IAudioOutputFactory AudioOutputFactory { get; private set; }
|
|
31
|
-
|
|
32
|
-
/// <summary>
|
|
33
|
-
/// There is a <see cref="IAudioOutput"/> for each peer that gets
|
|
34
|
-
/// created using the provided <see cref="AudioOutputFactory"/>
|
|
35
|
-
/// The <see cref="IAudioOutput"/> instance corresponding to a peer is
|
|
36
|
-
/// responsible for playing the audio that we receive that peer.
|
|
37
|
-
/// </summary>
|
|
38
|
-
public Dictionary<short, IAudioOutput> PeerOutputs;
|
|
39
|
-
|
|
40
|
-
/// <summary>
|
|
41
|
-
/// The current <see cref="ChatroomAgentMode"/> of this agent
|
|
42
|
-
/// </summary>
|
|
43
|
-
public ChatroomAgentMode CurrentMode { get; private set; }
|
|
44
|
-
|
|
45
|
-
/// <summary>
|
|
46
|
-
/// Mutes all the peers. If set to true, no incoming audio from other
|
|
47
|
-
/// peers will be played. If you want to selectively mute a peer, use
|
|
48
|
-
/// the <see cref="ChatroomPeerSettings.muteThem"/> flag in the
|
|
49
|
-
/// <see cref="PeerSettings"/> instance for that peer.
|
|
50
|
-
/// Note that setting this will not change <see cref="PeerSettings"/>
|
|
51
|
-
/// </summary>
|
|
52
|
-
public bool MuteOthers { get; set; }
|
|
53
|
-
|
|
54
|
-
/// <summary>
|
|
55
|
-
/// Whether this agent is muted or not. If set to true, voice data will
|
|
56
|
-
/// not be sent to ANY peer. If you want to selectively mute yourself
|
|
57
|
-
/// to a peer, use the <see cref="ChatroomPeerSettings.muteSelf"/>
|
|
58
|
-
/// flag in the <see cref="PeerSettings"/> instance for that peer.
|
|
59
|
-
/// Note that setting this will not change <see cref="PeerSettings"/>
|
|
60
|
-
/// </summary>
|
|
61
|
-
public bool MuteSelf { get; set; }
|
|
62
|
-
|
|
63
|
-
/// <summary>
|
|
64
|
-
/// <see cref="ChatroomPeerSettings"/> for each peer which allows you
|
|
65
|
-
/// to read or change the settings for a specific peer. Use [id] to get
|
|
66
|
-
/// settings for a peer with ID id;
|
|
67
|
-
/// </summary>
|
|
68
|
-
public Dictionary<short, ChatroomPeerSettings> PeerSettings;
|
|
69
|
-
#endregion
|
|
70
|
-
|
|
71
|
-
// ====================================================================
|
|
72
|
-
#region CONSTRUCTION / DISPOSAL
|
|
73
|
-
// ====================================================================
|
|
74
|
-
/// <summary>
|
|
75
|
-
/// Creates and returns a new agent using the provided dependencies.
|
|
76
|
-
/// The instance then makes the dependencies work together.
|
|
77
|
-
/// </summary>
|
|
78
|
-
///
|
|
79
|
-
/// <param name="chatroomNetwork">The chatroom network implementation
|
|
80
|
-
/// for chatroom access and sending data to peers in a chatroom.
|
|
81
|
-
/// </param>
|
|
82
|
-
///
|
|
83
|
-
/// <param name="audioInput">The source of the outgoing audio</param>
|
|
84
|
-
///
|
|
85
|
-
/// <param name="audioOutputFactory">
|
|
86
|
-
/// The factory used for creating <see cref="IAudioOutput"/> instances
|
|
87
|
-
/// for peers so that incoming audio from peers can be played.
|
|
88
|
-
/// </param>
|
|
89
|
-
public ChatroomAgent(
|
|
90
|
-
IChatroomNetwork chatroomNetwork,
|
|
91
|
-
IAudioInput audioInput,
|
|
92
|
-
IAudioOutputFactory audioOutputFactory
|
|
93
|
-
) {
|
|
94
|
-
AudioInput = audioInput ??
|
|
95
|
-
throw new ArgumentNullException(nameof(audioInput));
|
|
96
|
-
|
|
97
|
-
Network = chatroomNetwork ??
|
|
98
|
-
throw new ArgumentNullException(nameof(chatroomNetwork));
|
|
99
|
-
|
|
100
|
-
AudioOutputFactory = audioOutputFactory ??
|
|
101
|
-
throw new ArgumentNullException(nameof(audioOutputFactory));
|
|
102
|
-
|
|
103
|
-
CurrentMode = ChatroomAgentMode.Unconnected;
|
|
104
|
-
MuteOthers = false;
|
|
105
|
-
MuteSelf = false;
|
|
106
|
-
PeerSettings = new Dictionary<short, ChatroomPeerSettings>();
|
|
107
|
-
PeerOutputs = new Dictionary<short, IAudioOutput>();
|
|
108
|
-
|
|
109
|
-
LinkDependencies();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/// <summary>
|
|
113
|
-
/// Disposes the instance. WARNING: Calling this method will
|
|
114
|
-
/// also dispose the dependencies passed to it in the constructor.
|
|
115
|
-
/// Be mindful of this if you're sharing dependencies between multiple
|
|
116
|
-
/// instances and/or using them outside this instance.
|
|
117
|
-
/// </summary>
|
|
118
|
-
public void Dispose() {
|
|
119
|
-
AudioInput.Dispose();
|
|
120
|
-
|
|
121
|
-
RemoveAllPeers();
|
|
122
|
-
PeerSettings.Clear();
|
|
123
|
-
PeerOutputs.Clear();
|
|
124
|
-
|
|
125
|
-
Network.Dispose();
|
|
126
|
-
}
|
|
127
|
-
#endregion
|
|
128
|
-
|
|
129
|
-
// ====================================================================
|
|
130
|
-
#region INTERNAL
|
|
131
|
-
// ====================================================================
|
|
132
|
-
void LinkDependencies() {
|
|
133
|
-
// Network events
|
|
134
|
-
Network.OnCreatedChatroom += () =>
|
|
135
|
-
CurrentMode = ChatroomAgentMode.Host;
|
|
136
|
-
Network.OnClosedChatroom += () => {
|
|
137
|
-
CurrentMode = ChatroomAgentMode.Unconnected;
|
|
138
|
-
RemoveAllPeers();
|
|
139
|
-
};
|
|
140
|
-
Network.OnJoinedChatroom += id => {
|
|
141
|
-
CurrentMode = ChatroomAgentMode.Guest;
|
|
142
|
-
};
|
|
143
|
-
Network.OnLeftChatroom += () => {
|
|
144
|
-
RemoveAllPeers();
|
|
145
|
-
CurrentMode = ChatroomAgentMode.Unconnected;
|
|
146
|
-
};
|
|
147
|
-
Network.OnPeerJoinedChatroom += id =>
|
|
148
|
-
AddPeer(id);
|
|
149
|
-
Network.OnPeerLeftChatroom += id =>
|
|
150
|
-
RemovePeer(id);
|
|
151
|
-
|
|
152
|
-
// Stream the incoming audio data using the right peer output
|
|
153
|
-
Network.OnAudioReceived += (peerID, data) => {
|
|
154
|
-
// if we're muting all, no point continuing.
|
|
155
|
-
if (MuteOthers) return;
|
|
156
|
-
|
|
157
|
-
var index = data.segmentIndex;
|
|
158
|
-
var frequency = data.frequency;
|
|
159
|
-
var channels = data.channelCount;
|
|
160
|
-
var samples = data.samples;
|
|
161
|
-
|
|
162
|
-
if (PeerSettings.ContainsKey(peerID) && !PeerSettings[peerID].muteThem)
|
|
163
|
-
PeerOutputs[peerID].Feed(index, frequency, channels, samples);
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
AudioInput.OnSegmentReady += (index, samples) => {
|
|
167
|
-
// If we're muting ourselves to all, no point continuing
|
|
168
|
-
if (MuteSelf) return;
|
|
169
|
-
|
|
170
|
-
// Get all the recipients we haven't muted ourselves to
|
|
171
|
-
var recipients = Network.PeerIDs
|
|
172
|
-
.Where(x => PeerSettings.ContainsKey(x) && !PeerSettings[x].muteSelf);
|
|
173
|
-
|
|
174
|
-
// Send the audio segment to every deserving recipient
|
|
175
|
-
foreach (var recipient in recipients)
|
|
176
|
-
Network.SendAudioSegment(recipient, new ChatroomAudioSegment {
|
|
177
|
-
segmentIndex = index,
|
|
178
|
-
frequency = AudioInput.Frequency,
|
|
179
|
-
channelCount = AudioInput.ChannelCount,
|
|
180
|
-
samples = samples
|
|
181
|
-
});
|
|
182
|
-
};
|
|
183
|
-
}
|
|
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
|
-
|
|
199
|
-
void RemovePeer(short id) {
|
|
200
|
-
if (PeerSettings.ContainsKey(id))
|
|
201
|
-
PeerSettings.Remove(id);
|
|
202
|
-
if (PeerOutputs.ContainsKey(id)) {
|
|
203
|
-
PeerOutputs[id].Dispose();
|
|
204
|
-
PeerOutputs.Remove(id);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
void RemoveAllPeers() {
|
|
209
|
-
var peers = Network.PeerIDs;
|
|
210
|
-
foreach(var peer in peers)
|
|
211
|
-
RemovePeer(peer);
|
|
212
|
-
}
|
|
213
|
-
#endregion
|
|
214
|
-
}
|
|
215
|
-
}
|
package/Runtime/Extensions.cs
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
using System.Collections.Generic;
|
|
2
|
-
|
|
3
|
-
using UnityEngine;
|
|
4
|
-
|
|
5
|
-
namespace Adrenak.UniVoice {
|
|
6
|
-
public static class Extensions {
|
|
7
|
-
/// <summary>
|
|
8
|
-
/// Returns the normalized position of the AudioSource on its AudioClip
|
|
9
|
-
/// </summary>
|
|
10
|
-
public static float GetCurrentPosition(this AudioSource source) {
|
|
11
|
-
return (float)source.timeSamples / source.clip.samples;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/// <summary>
|
|
15
|
-
/// Adds the given key to the dictionary with a value if the key
|
|
16
|
-
/// is not present before.
|
|
17
|
-
/// </summary>
|
|
18
|
-
/// <param name="t">The key to check and add</param>
|
|
19
|
-
/// <param name="k">The value if the key is added</param>
|
|
20
|
-
public static void EnsureKey<T, K>
|
|
21
|
-
(this Dictionary<T, K> dict, T t, K k) {
|
|
22
|
-
if (!dict.ContainsKey(t))
|
|
23
|
-
dict.Add(t, k);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/// <summary>
|
|
27
|
-
/// Ensures a key and value pair are in the dictionary
|
|
28
|
-
/// </summary>
|
|
29
|
-
/// <param name="t">The key to ensure</param>
|
|
30
|
-
/// <param name="k">The value associated with the key</param>
|
|
31
|
-
public static void EnsurePair<T, K>
|
|
32
|
-
(this Dictionary<T, K> dict, T t, K k) {
|
|
33
|
-
if (dict.ContainsKey(t))
|
|
34
|
-
dict[t] = k;
|
|
35
|
-
else
|
|
36
|
-
dict.Add(t, k);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
2
|
-
guid: 646602ab062d77543b3742e51d16658f
|
|
3
|
-
timeCreated: 1547895114
|
|
4
|
-
licenseType: Free
|
|
5
|
-
MonoImporter:
|
|
6
|
-
serializedVersion: 2
|
|
7
|
-
defaultReferences: []
|
|
8
|
-
executionOrder: 0
|
|
9
|
-
icon: {instanceID: 0}
|
|
10
|
-
userData:
|
|
11
|
-
assetBundleName:
|
|
12
|
-
assetBundleVariant:
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using System.Collections.Generic;
|
|
3
|
-
|
|
4
|
-
namespace Adrenak.UniVoice {
|
|
5
|
-
/// <summary>
|
|
6
|
-
/// A chatroom specific networking interface for creating & joining
|
|
7
|
-
/// chatrooms and sending & receiving data to and from chatroom peers.
|
|
8
|
-
/// </summary>
|
|
9
|
-
public interface IChatroomNetwork : IDisposable {
|
|
10
|
-
// ====================================================================
|
|
11
|
-
#region EVENTS
|
|
12
|
-
// ====================================================================
|
|
13
|
-
/// <summary>
|
|
14
|
-
/// Fired when a chatroom is created.
|
|
15
|
-
/// </summary>
|
|
16
|
-
event Action OnCreatedChatroom;
|
|
17
|
-
|
|
18
|
-
/// <summary>
|
|
19
|
-
/// Fired when the attempt to create a chatroom fails.
|
|
20
|
-
/// Provides an exception as event data.
|
|
21
|
-
/// </summary>
|
|
22
|
-
event Action<Exception> OnChatroomCreationFailed;
|
|
23
|
-
|
|
24
|
-
/// <summary>
|
|
25
|
-
/// Fired when a chatroom is closed.
|
|
26
|
-
/// </summary>
|
|
27
|
-
event Action OnClosedChatroom;
|
|
28
|
-
|
|
29
|
-
/// <summary>
|
|
30
|
-
/// Fired when the local user joins a chatroom.
|
|
31
|
-
/// Provides the chatroom ID assigned as event data.
|
|
32
|
-
/// </summary>
|
|
33
|
-
event Action<short> OnJoinedChatroom;
|
|
34
|
-
|
|
35
|
-
/// <summary>
|
|
36
|
-
/// Fired when an attempt to join a chatroom fails.
|
|
37
|
-
/// Provides an exception as event data.
|
|
38
|
-
/// </summary>
|
|
39
|
-
event Action<Exception> OnChatroomJoinFailed;
|
|
40
|
-
|
|
41
|
-
/// <summary>
|
|
42
|
-
/// Fired when the local user leaves a chatroom
|
|
43
|
-
/// </summary>
|
|
44
|
-
event Action OnLeftChatroom;
|
|
45
|
-
|
|
46
|
-
/// <summary>
|
|
47
|
-
/// Fired when a peer joins the chatroom.
|
|
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.
|
|
51
|
-
/// </summary>
|
|
52
|
-
event Action<short> OnPeerJoinedChatroom;
|
|
53
|
-
|
|
54
|
-
/// <summary>
|
|
55
|
-
/// Fired when a peer leaves the chatroom.
|
|
56
|
-
/// Provides the ID of the peer as event data.
|
|
57
|
-
/// This also also MUST be called for all peers
|
|
58
|
-
/// when we leave a network.
|
|
59
|
-
/// </summary>
|
|
60
|
-
event Action<short> OnPeerLeftChatroom;
|
|
61
|
-
|
|
62
|
-
/// <summary>
|
|
63
|
-
/// Fired when the network receives audio data from a peer.
|
|
64
|
-
/// </summary>
|
|
65
|
-
event Action<short, ChatroomAudioSegment> OnAudioReceived;
|
|
66
|
-
|
|
67
|
-
/// <summary>
|
|
68
|
-
/// Fired when the local user sets audio data to a peer.
|
|
69
|
-
/// </summary>
|
|
70
|
-
event Action<short, ChatroomAudioSegment> OnAudioSent;
|
|
71
|
-
#endregion
|
|
72
|
-
|
|
73
|
-
// ====================================================================
|
|
74
|
-
#region PROPERTIES
|
|
75
|
-
// ====================================================================
|
|
76
|
-
/// <summary>
|
|
77
|
-
/// The ID of the local user in the current chatroom
|
|
78
|
-
/// </summary>
|
|
79
|
-
short OwnID { get; }
|
|
80
|
-
|
|
81
|
-
/// <summary>
|
|
82
|
-
/// IDs of all the peers in the current chatroom (excluding <see cref="OwnID"/>)
|
|
83
|
-
/// </summary>
|
|
84
|
-
List<short> PeerIDs { get; }
|
|
85
|
-
#endregion
|
|
86
|
-
|
|
87
|
-
// ====================================================================
|
|
88
|
-
#region METHODS
|
|
89
|
-
// ====================================================================
|
|
90
|
-
/// <summary>
|
|
91
|
-
/// Creates a chatroom
|
|
92
|
-
/// </summary>
|
|
93
|
-
/// <param name="data">Any arguments for hosting a chatroom</param>
|
|
94
|
-
void HostChatroom(object data = null);
|
|
95
|
-
|
|
96
|
-
/// <summary>
|
|
97
|
-
/// Closes a chatroom that the local user is hosting
|
|
98
|
-
/// </summary>
|
|
99
|
-
/// <param name="data">Any arguments for closing the room</param>
|
|
100
|
-
void CloseChatroom(object data = null);
|
|
101
|
-
|
|
102
|
-
/// <summary>
|
|
103
|
-
/// Joins a chatroom
|
|
104
|
-
/// </summary>
|
|
105
|
-
/// <param name="data">The name of the chatroom to join</param>
|
|
106
|
-
void JoinChatroom(object data = null);
|
|
107
|
-
|
|
108
|
-
/// <summary>
|
|
109
|
-
/// Leaves the chatroom the local user is currently in, if any
|
|
110
|
-
/// </summary>
|
|
111
|
-
/// <param name="data">Any arguments for leaving the room</param>
|
|
112
|
-
void LeaveChatroom(object data = null);
|
|
113
|
-
|
|
114
|
-
/// <summary>
|
|
115
|
-
/// Sends audio data over the network
|
|
116
|
-
/// </summary>
|
|
117
|
-
/// <param name="data">The data to be transmitted.</param>
|
|
118
|
-
void SendAudioSegment(short peerID, ChatroomAudioSegment data);
|
|
119
|
-
#endregion
|
|
120
|
-
}
|
|
121
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
namespace Adrenak.UniVoice {
|
|
2
|
-
[System.Serializable]
|
|
3
|
-
/// <summary>
|
|
4
|
-
/// Represents the mode that a <see cref="ChatroomAgent"/> is in.
|
|
5
|
-
/// </summary>
|
|
6
|
-
public enum ChatroomAgentMode {
|
|
7
|
-
/// <summary>
|
|
8
|
-
/// The agent is neither connected to a chatroom nor hosting one.
|
|
9
|
-
/// </summary>
|
|
10
|
-
Unconnected,
|
|
11
|
-
|
|
12
|
-
/// <summary>
|
|
13
|
-
/// The agent is hosting a chatroom. May or may not have guests
|
|
14
|
-
/// </summary>
|
|
15
|
-
Host,
|
|
16
|
-
|
|
17
|
-
/// <summary>
|
|
18
|
-
/// The agent has joined a chatroom and is a guest there
|
|
19
|
-
/// </summary>
|
|
20
|
-
Guest
|
|
21
|
-
}
|
|
22
|
-
}
|