This repository has been archived by the owner on Feb 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Switch Channel, Fixed: "|" not working, Refactoring
- Loading branch information
Showing
20 changed files
with
556 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
streamdeck-teamspeak3integration/Actions/TeamSpeak3ChannelSwitchAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
using BarRaider.SdTools; | ||
|
||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
using streamdeck_client_csharp; | ||
using streamdeck_client_csharp.Events; | ||
|
||
using ZerGo0.TeamSpeak3Integration.Helpers; | ||
|
||
using KeyPayload = BarRaider.SdTools.KeyPayload; | ||
|
||
namespace ZerGo0.TeamSpeak3Integration.Actions | ||
{ | ||
[PluginActionId("com.zergo0.teamspeak3integration.channelswitch")] | ||
public class TeamSpeak3ChannelSwitchAction : PluginBase | ||
{ | ||
public TeamSpeak3ChannelSwitchAction(SDConnection connection, InitialPayload payload) : base(connection, payload) | ||
{ | ||
if (payload.Settings == null || payload.Settings.Count == 0) | ||
_settings = PluginSettings.CreateDefaultSettings(); | ||
else | ||
_settings = payload.Settings.ToObject<PluginSettings>(); | ||
connection.StreamDeckConnection.OnSendToPlugin += StreamDeckConnection_OnSendToPlugin; | ||
|
||
SaveSettings(); | ||
} | ||
|
||
public override void Dispose() | ||
{ | ||
TeamSpeak3Telnet.TS3_CLIENT?.Dispose(); | ||
Connection.StreamDeckConnection.OnSendToPlugin -= StreamDeckConnection_OnSendToPlugin; | ||
Logger.Instance.LogMessage(TracingLevel.INFO, "Destructor called"); | ||
} | ||
|
||
public override async void KeyPressed(KeyPayload payload) | ||
{ | ||
Logger.Instance.LogMessage(TracingLevel.INFO, "Key Pressed"); | ||
|
||
try | ||
{ | ||
if (TeamSpeak3Telnet.TS3_CLIENT == null || !TeamSpeak3Telnet.TS3_CLIENT.IsConnected) | ||
{ | ||
TeamSpeak3Telnet.SetupTelnetClient(_settings.ApiKey); | ||
if (TeamSpeak3Telnet.TS3_CLIENT == null) return; | ||
} | ||
|
||
ChannelSwitch(); | ||
} | ||
catch (Exception) | ||
{ | ||
TeamSpeak3Telnet.TS3_CLIENT?.Dispose(); | ||
TeamSpeak3Telnet.TS3_CLIENT = null; | ||
} | ||
} | ||
|
||
public override void KeyReleased(KeyPayload payload) | ||
{ | ||
} | ||
|
||
public override async void OnTick() | ||
{ | ||
} | ||
|
||
public override void ReceivedSettings(ReceivedSettingsPayload payload) | ||
{ | ||
Tools.AutoPopulateSettings(_settings, payload.Settings); | ||
SaveSettings(); | ||
} | ||
|
||
public override void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload) | ||
{ | ||
} | ||
|
||
private class PluginSettings | ||
{ | ||
[JsonProperty(PropertyName = "apiKey")] | ||
public string ApiKey { get; set; } | ||
|
||
[JsonProperty(PropertyName = "channelName")] | ||
public string ChannelName { get; set; } | ||
|
||
public static PluginSettings CreateDefaultSettings() | ||
{ | ||
var instance = new PluginSettings | ||
{ | ||
ApiKey = string.Empty, | ||
ChannelName = string.Empty | ||
}; | ||
|
||
return instance; | ||
} | ||
} | ||
|
||
#region Private Members | ||
|
||
private readonly PluginSettings _settings; | ||
|
||
#endregion | ||
|
||
#region Private Methods | ||
|
||
private Task SaveSettings() | ||
{ | ||
return Connection.SetSettingsAsync(JObject.FromObject(_settings)); | ||
} | ||
|
||
private void StreamDeckConnection_OnSendToPlugin(object sender, | ||
StreamDeckEventReceivedEventArgs<SendToPluginEvent> e) | ||
{ | ||
var payload = e.Event.Payload; | ||
if (Connection.ContextId != e.Event.Context) return; | ||
} | ||
|
||
private void ChannelSwitch() | ||
{ | ||
try | ||
{ | ||
var clientId = TeamSpeak3Telnet.GetClientId(); | ||
if (clientId == -1) | ||
{ | ||
TeamSpeak3Telnet.TS3_CLIENT?.Dispose(); | ||
TeamSpeak3Telnet.TS3_CLIENT = null; | ||
return; | ||
} | ||
|
||
TeamSpeak3Telnet.ChannelSwitch(_settings.ChannelName, clientId); | ||
} | ||
catch (Exception) | ||
{ | ||
TeamSpeak3Telnet.TS3_CLIENT?.Dispose(); | ||
TeamSpeak3Telnet.TS3_CLIENT = null; | ||
} | ||
} | ||
|
||
#endregion | ||
} | ||
} |
Oops, something went wrong.