Skip to content

Commit

Permalink
- Adding additional auto-connectivity logic for certain services
Browse files Browse the repository at this point in the history
  • Loading branch information
SaviorXTanren committed Sep 30, 2023
1 parent 610a3b8 commit adb0092
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 47 deletions.
52 changes: 30 additions & 22 deletions MixItUp.Base/Model/Actions/LumiaStreamActionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,34 +67,42 @@ private LumiaStreamActionModel() { }

protected override async Task PerformInternal(CommandParametersModel parameters)
{
if (this.ActionType == LumiaStreamActionTypeEnum.TriggerCommand)
if (ServiceManager.Get<LumiaStreamService>().IsEnabled && !ServiceManager.Get<LumiaStreamService>().IsConnected)
{
string commandType = null;
switch (this.CommandType)
await ServiceManager.Get<LumiaStreamService>().Connect();
}

if (ServiceManager.Get<LumiaStreamService>().IsConnected)
{
if (this.ActionType == LumiaStreamActionTypeEnum.TriggerCommand)
{
case LumiaStreamActionCommandTypeEnum.ChatCommand:
commandType = "chat-command";
break;
case LumiaStreamActionCommandTypeEnum.TwitchPoint:
commandType = "twitch-points";
break;
case LumiaStreamActionCommandTypeEnum.TwitchExtension:
commandType = "twitch-extension";
break;
case LumiaStreamActionCommandTypeEnum.TrovoSpell:
commandType = "trovo-spells";
break;
}
string commandType = null;
switch (this.CommandType)
{
case LumiaStreamActionCommandTypeEnum.ChatCommand:
commandType = "chat-command";
break;
case LumiaStreamActionCommandTypeEnum.TwitchPoint:
commandType = "twitch-points";
break;
case LumiaStreamActionCommandTypeEnum.TwitchExtension:
commandType = "twitch-extension";
break;
case LumiaStreamActionCommandTypeEnum.TrovoSpell:
commandType = "trovo-spells";
break;
}

if (!string.IsNullOrEmpty(commandType))
if (!string.IsNullOrEmpty(commandType))
{
await ServiceManager.Get<LumiaStreamService>().TriggerCommand(commandType, this.CommandName);
}
}
else if (this.ActionType == LumiaStreamActionTypeEnum.SetLightsColor)
{
await ServiceManager.Get<LumiaStreamService>().TriggerCommand(commandType, this.CommandName);
await ServiceManager.Get<LumiaStreamService>().SetColorAndBrightness(this.ColorHex, this.ColorBrightness, (int)(this.ColorTransition * 1000), (int)(this.ColorDuration * 1000), this.ColorHold);
}
}
else if (this.ActionType == LumiaStreamActionTypeEnum.SetLightsColor)
{
await ServiceManager.Get<LumiaStreamService>().SetColorAndBrightness(this.ColorHex, this.ColorBrightness, (int)(this.ColorTransition * 1000), (int)(this.ColorDuration * 1000), this.ColorHold);
}
}
}
}
5 changes: 5 additions & 0 deletions MixItUp.Base/Model/Actions/SAMMIActionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public SAMMIActionModel() { }

protected override async Task PerformInternal(CommandParametersModel parameters)
{
if (ServiceManager.Get<SAMMIService>().IsEnabled && !ServiceManager.Get<SAMMIService>().IsConnected)
{
await ServiceManager.Get<SAMMIService>().Connect();
}

if (ServiceManager.Get<SAMMIService>().IsConnected)
{
if (this.ActionType == SAMMIActionTypeEnum.TriggerButton || this.ActionType == SAMMIActionTypeEnum.ReleaseButton)
Expand Down
8 changes: 2 additions & 6 deletions MixItUp.Base/Model/Actions/TITSActionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,9 @@ public TITSActionModel() { }

protected override async Task PerformInternal(CommandParametersModel parameters)
{
if (ChannelSession.Settings.TITSOAuthToken != null && !ServiceManager.Get<TITSService>().IsConnected)
if (ServiceManager.Get<TITSService>().IsEnabled && !ServiceManager.Get<TITSService>().IsConnected)
{
Result result = await ServiceManager.Get<TITSService>().Connect(ChannelSession.Settings.TITSOAuthToken);
if (!result.Success)
{
return;
}
await ServiceManager.Get<TITSService>().Connect();
}

if (ServiceManager.Get<TITSService>().IsConnected)
Expand Down
6 changes: 1 addition & 5 deletions MixItUp.Base/Model/Actions/VoicemodActionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ protected override async Task PerformInternal(CommandParametersModel parameters)
{
if (ChannelSession.Settings.EnableVoicemodStudio && !ServiceManager.Get<IVoicemodService>().IsConnected)
{
Result result = await ServiceManager.Get<IVoicemodService>().Connect();
if (!result.Success)
{
return;
}
await ServiceManager.Get<IVoicemodService>().Connect();
}

if (ServiceManager.Get<IVoicemodService>().IsConnected)
Expand Down
2 changes: 2 additions & 0 deletions MixItUp.Base/Services/External/LumiaStreamService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public LumiaStreamService() { }

public string Name { get { return MixItUp.Base.Resources.LumiaStream; } }

public bool IsEnabled { get { return ChannelSession.Settings.LumiaStreamOAuthToken != null; } }

public bool IsConnected { get; private set; }

public async Task<Result> Connect()
Expand Down
2 changes: 2 additions & 0 deletions MixItUp.Base/Services/External/SAMMIService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class SAMMIService : IExternalService

public string Name { get { return Resources.SAMMI; } }

public bool IsEnabled { get { return ChannelSession.Settings.EnableSAMMI; } }

public bool IsConnected { get; private set; }

public async Task<Result> Connect()
Expand Down
18 changes: 4 additions & 14 deletions MixItUp.Base/Services/External/TITSService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ public TITSService() : base(string.Empty) { }

public override string Name { get { return MixItUp.Base.Resources.TwitchIntegratedThrowingSystem; } }

public bool IsEnabled { get { return ChannelSession.Settings.TITSOAuthToken != null; } }

public override async Task<Result> Connect()
{
try
{
this.token = null;
if (await this.ConnectWebSocket())
{
return await this.InitializeInternal();
Expand All @@ -135,19 +136,8 @@ public override async Task<Result> Connect()

public override async Task<Result> Connect(OAuthTokenModel token)
{
try
{
this.token = token;
if (await this.ConnectWebSocket())
{
return await this.InitializeInternal();
}
}
catch (Exception ex)
{
Logger.Log(ex);
}
return new Result(MixItUp.Base.Resources.TITSConnectionFailed);
this.token = token;
return await this.Connect();
}

public override async Task Disconnect()
Expand Down

0 comments on commit adb0092

Please sign in to comment.