Skip to content

Commit

Permalink
Merge branch 'v4'
Browse files Browse the repository at this point in the history
  • Loading branch information
adrenak committed Jan 12, 2025
2 parents 9858c2c + efbd843 commit 9826982
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 6,848 deletions.
27 changes: 27 additions & 0 deletions Assets/Adrenak.UniVoice/Runtime/ClientSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,28 @@
using UnityEngine;

namespace Adrenak.UniVoice {
/// <summary>
/// Handles a client session.
/// Requires an implementation of <see cref="IAudioClient{T}"/>, <see cref="IAudioInput"/> and <see cref="IAudioOutputFactory"/> each.
/// Allows adding input and output filters and handles their execution.
/// </summary>
/// <typeparam name="T"></typeparam>
public class ClientSession<T> : IDisposable {
/// <summary>
/// The <see cref="IAudioOutput"/> instances of each peer in the session
/// </summary>
public Dictionary<T, IAudioOutput> PeerOutputs { get; private set; } = new Dictionary<T, IAudioOutput>();

/// <summary>
/// The input <see cref="IAudioFilter"/> that will be applied to the outgoing audio for all the peers.
/// Note that filters are executed in the order they are present in this list
/// </summary>
public List<IAudioFilter> InputFilters { get; set; } = new List<IAudioFilter>();

/// <summary>
/// The output <see cref="IAudioFilter"/> that will be applied to the incoming audio for all the peers.
/// Note that filters are executed in the order they are present in this list.
/// </summary>
public List<IAudioFilter> OutputFilters { get; set; } = new List<IAudioFilter>();

public ClientSession(IAudioClient<T> client, IAudioInput input, IAudioOutputFactory outputFactory) {
Expand All @@ -16,6 +34,9 @@ public ClientSession(IAudioClient<T> client, IAudioInput input, IAudioOutputFact
OutputFactory = outputFactory;
}

/// <summary>
/// The <see cref="IAudioClient{T}"/> that's used for networking
/// </summary>
IAudioClient<T> client;
public IAudioClient<T> Client {
get => client;
Expand Down Expand Up @@ -63,6 +84,9 @@ public IAudioClient<T> Client {
}

IAudioInput input;
/// <summary>
/// The <see cref="IAudioInput"/> that's used for sourcing outgoing audio
/// </summary>
public IAudioInput Input {
get => input;
set {
Expand All @@ -81,6 +105,9 @@ public IAudioInput Input {
}

IAudioOutputFactory outputFactory;
/// <summary>
/// The <see cref="IAudioOutputFactory"/> that creates the <see cref="IAudioOutput"/> of peers
/// </summary>
public IAudioOutputFactory OutputFactory {
get => outputFactory;
set {
Expand Down
28 changes: 0 additions & 28 deletions Assets/Adrenak.UniVoice/Runtime/Common/Extensions.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Assets/Adrenak.UniVoice/Runtime/Common/Extensions.cs.meta

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using UnityEngine;

namespace Adrenak.UniVoice {
namespace Adrenak.UniVoice.Filters {
/// <summary>
/// A filter that applies Gaussian blur over audio data to smoothen it.
/// This is somewhat effective in removing noise from the audio.
Expand Down
2 changes: 1 addition & 1 deletion Assets/Adrenak.UniVoice/Runtime/Impl/Filters/OpusFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* encoding the size of audio data is much (over 10x) larger.
* For more info see https://www.github.com/adrenak/UnityOpus
*/
namespace Adrenak.UniVoice {
namespace Adrenak.UniVoice.Filters {
/// <summary>
/// A filter that encodes audio using Opus. Use this as an output filter
/// to reduce the size of outgoing client audio
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if UNIVOICE_MIRROR_NETWORK
#if UNIVOICE_MIRROR_NETWORK
using System;
using System.Linq;
using System.Collections.Generic;
Expand All @@ -7,7 +7,7 @@
using Adrenak.BRW;
using UnityEngine;

namespace Adrenak.UniVoice {
namespace Adrenak.UniVoice.Networks {
/// <summary>
/// Activate this class by including the UNIVOICE_MIRROR_NETWORK compilaton symbol
/// in your project.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using Mirror;

namespace Adrenak.UniVoice {
namespace Adrenak.UniVoice.Networks {
/// <summary>
/// The messages exchanged between the server and client.
/// To see how the Mirror implementation of UniVoice uses this struct
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#if UNIVOICE_MIRROR_NETWORK
namespace Adrenak.UniVoice {
namespace Adrenak.UniVoice.Networks {
/// <summary>
/// The different types of messages we send over Mirror
/// to implement the <see cref="IAudioClient{T}"/> and <see cref="IAudioServer{T}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using UnityEngine;

namespace Adrenak.UniVoice {
namespace Adrenak.UniVoice.Networks {
/// <summary>
/// Observes the mode of the Mirror NetworkManager and fires an event
/// when it changes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#if UNIVOICE_MIRROR_NETWORK
// Notes:
// In Mirror 89.11.0, the OnServerConnectedWithAddress event was added
// https://github.com/MirrorNetworking/Mirror/releases/tag/v89.11.0
// OnServerConnected no longer seems to work?

#if UNIVOICE_MIRROR_NETWORK
using System;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -9,7 +14,7 @@
using Mirror;
using Adrenak.BRW;

namespace Adrenak.UniVoice {
namespace Adrenak.UniVoice.Networks {
/// <summary>
/// Activate this class by including the UNIVOICE_MIRROR_NETWORK compilaton symbol
/// in your project.
Expand Down Expand Up @@ -39,15 +44,25 @@ public MirrorServer() {
mirrorEvents.ModeChanged += OnModeChanged;

NetworkServer.RegisterHandler<MirrorMessage>(OnReceivedMessage, false);

#if MIRROR_89_OR_NEWER
NetworkManager.singleton.transport.OnServerConnectedWithAddress += OnServerConnected;
#else
NetworkManager.singleton.transport.OnServerConnected += OnServerConnected;
#endif
NetworkManager.singleton.transport.OnServerDisconnected += OnServerDisconnected;
}

void IDisposable.Dispose() {
mirrorEvents.ModeChanged -= OnModeChanged;

NetworkServer.UnregisterHandler<MirrorMessage>();

#if MIRROR_89_OR_NEWER
NetworkManager.singleton.transport.OnServerConnectedWithAddress -= OnServerConnected;
#else
NetworkManager.singleton.transport.OnServerConnected -= OnServerConnected;
#endif
NetworkManager.singleton.transport.OnServerDisconnected -= OnServerDisconnected;
}

Expand Down Expand Up @@ -126,7 +141,11 @@ void OnReceivedMessage(NetworkConnectionToClient connection, MirrorMessage messa
}

// When a new Mirror client connects
#if MIRROR_89_OR_NEWER
void OnServerConnected(int connId, string addr) {
#else
void OnServerConnected(int connId) {
#endif
NetworkServer.ReplaceHandler<MirrorMessage>(OnReceivedMessage, false);

Debug.unityLogger.Log(LogType.Log, TAG, $"Client {connId} connected");
Expand Down
Loading

0 comments on commit 9826982

Please sign in to comment.