69 lines
2.1 KiB
C#
69 lines
2.1 KiB
C#
using Agora.Rtc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Prism.Ioc;
|
|
using Prism.Events;
|
|
using Demo.Common.Events;
|
|
using Masuit.Tools;
|
|
|
|
namespace Demo.Common.Helpers
|
|
{
|
|
public class RtcEngineEventHandler : IRtcEngineEventHandler
|
|
{
|
|
private readonly IEventAggregator aggregator;
|
|
public RtcEngineEventHandler()
|
|
{
|
|
aggregator = ContainerLocator.Container.Resolve<IEventAggregator>();
|
|
}
|
|
|
|
public override void OnUserJoined(RtcConnection connection, uint remoteUid, int elapsed)
|
|
{
|
|
//base.OnUserJoined(connection, remoteUid, elapsed);
|
|
Console.WriteLine($@"新用户加入: channelId:{connection.channelId} localuid: {connection.localUid} remoteuid:{remoteUid} elapsed: {elapsed}");
|
|
|
|
|
|
//var aggregator = ContainerLocator.Container.Resolve<IEventAggregator>();
|
|
aggregator.GetEvent<UserJoinEvent>().Publish(new Models.User
|
|
{
|
|
Id = remoteUid,
|
|
UserName = remoteUid.ToString(),
|
|
IsManager = true,
|
|
IsLocal = false
|
|
});
|
|
}
|
|
|
|
|
|
public override void OnUserOffline(RtcConnection connection, uint remoteUid, USER_OFFLINE_REASON_TYPE reason)
|
|
{
|
|
//var aggregator = ContainerLocator.Container.Resolve<IEventAggregator>();
|
|
aggregator.GetEvent<UserLeaveEvent>().Publish(new Models.User
|
|
{
|
|
Id = remoteUid,
|
|
UserName = remoteUid.ToString(),
|
|
IsManager = true,
|
|
IsLocal = false
|
|
});
|
|
}
|
|
|
|
public override void OnAudioVolumeIndication(RtcConnection connection, AudioVolumeInfo[] speakers, uint speakerNumber, int totalVolume)
|
|
{
|
|
if (speakers.Length <= 0)
|
|
{
|
|
return;
|
|
}
|
|
speakers.ForEach(sp =>
|
|
{
|
|
sp.uid = sp.uid == 0 ? AgoraHelper._localUId : sp.uid;
|
|
|
|
|
|
aggregator.GetEvent<AudioVolumeIndicationEvent>().Publish(sp);
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
}
|