Added hermes websocket support. Added chat command support. Added selectable voice command via websocket. Added websocket heartbeat management.
This commit is contained in:
@ -3,8 +3,8 @@ namespace TwitchChatTTS.OBS.Socket.Data
|
||||
[Serializable]
|
||||
public class EventMessage
|
||||
{
|
||||
public string eventType { get; set; }
|
||||
public int eventIntent { get; set; }
|
||||
public Dictionary<string, object> eventData { get; set; }
|
||||
public string EventType { get; set; }
|
||||
public int EventIntent { get; set; }
|
||||
public Dictionary<string, object> EventData { get; set; }
|
||||
}
|
||||
}
|
@ -3,13 +3,13 @@ namespace TwitchChatTTS.OBS.Socket.Data
|
||||
[Serializable]
|
||||
public class HelloMessage
|
||||
{
|
||||
public string obsWebSocketVersion { get; set; }
|
||||
public int rpcVersion { get; set; }
|
||||
public AuthenticationMessage authentication { get; set; }
|
||||
public string ObsWebSocketVersion { get; set; }
|
||||
public int RpcVersion { get; set; }
|
||||
public AuthenticationMessage Authentication { get; set; }
|
||||
}
|
||||
|
||||
public class AuthenticationMessage {
|
||||
public string challenge { get; set; }
|
||||
public string salt { get; set; }
|
||||
public string Challenge { get; set; }
|
||||
public string Salt { get; set; }
|
||||
}
|
||||
}
|
@ -3,6 +3,6 @@ namespace TwitchChatTTS.OBS.Socket.Data
|
||||
[Serializable]
|
||||
public class IdentifiedMessage
|
||||
{
|
||||
public int negotiatedRpcVersion { get; set; }
|
||||
public int NegotiatedRpcVersion { get; set; }
|
||||
}
|
||||
}
|
@ -3,14 +3,14 @@ namespace TwitchChatTTS.OBS.Socket.Data
|
||||
[Serializable]
|
||||
public class IdentifyMessage
|
||||
{
|
||||
public int rpcVersion { get; set; }
|
||||
public string? authentication { get; set; }
|
||||
public int eventSubscriptions { get; set; }
|
||||
public int RpcVersion { get; set; }
|
||||
public string? Authentication { get; set; }
|
||||
public int EventSubscriptions { get; set; }
|
||||
|
||||
public IdentifyMessage(int version, string auth, int subscriptions) {
|
||||
rpcVersion = version;
|
||||
authentication = auth;
|
||||
eventSubscriptions = subscriptions;
|
||||
RpcVersion = version;
|
||||
Authentication = auth;
|
||||
EventSubscriptions = subscriptions;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,14 +3,14 @@ namespace TwitchChatTTS.OBS.Socket.Data
|
||||
[Serializable]
|
||||
public class RequestMessage
|
||||
{
|
||||
public string requestType { get; set; }
|
||||
public string requestId { get; set; }
|
||||
public Dictionary<string, object> requestData { get; set; }
|
||||
public string RequestType { get; set; }
|
||||
public string RequestId { get; set; }
|
||||
public Dictionary<string, object> RequestData { get; set; }
|
||||
|
||||
public RequestMessage(string type, string id, Dictionary<string, object> data) {
|
||||
requestType = type;
|
||||
requestId = id;
|
||||
requestData = data;
|
||||
RequestType = type;
|
||||
RequestId = id;
|
||||
RequestData = data;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,9 +3,9 @@ namespace TwitchChatTTS.OBS.Socket.Data
|
||||
[Serializable]
|
||||
public class RequestResponseMessage
|
||||
{
|
||||
public string requestType { get; set; }
|
||||
public string requestId { get; set; }
|
||||
public object requestStatus { get; set; }
|
||||
public Dictionary<string, object> responseData { get; set; }
|
||||
public string RequestType { get; set; }
|
||||
public string RequestId { get; set; }
|
||||
public object RequestStatus { get; set; }
|
||||
public Dictionary<string, object> ResponseData { get; set; }
|
||||
}
|
||||
}
|
@ -21,15 +21,15 @@ namespace TwitchChatTTS.OBS.Socket.Handlers
|
||||
if (message is not EventMessage obj || obj == null)
|
||||
return;
|
||||
|
||||
switch (obj.eventType) {
|
||||
switch (obj.EventType) {
|
||||
case "StreamStateChanged":
|
||||
case "RecordStateChanged":
|
||||
if (sender is not OBSSocketClient client)
|
||||
return;
|
||||
|
||||
string? raw_state = obj.eventData["outputState"].ToString();
|
||||
string? raw_state = obj.EventData["outputState"].ToString();
|
||||
string? state = raw_state?.Substring(21).ToLower();
|
||||
client.Live = obj.eventData["outputActive"].ToString() == "True";
|
||||
client.Live = obj.EventData["outputActive"].ToString() == "True";
|
||||
Logger.LogWarning("Stream " + (state != null && state.EndsWith("ing") ? "is " : "has ") + state + ".");
|
||||
|
||||
if (client.Live == false && state != null && !state.EndsWith("ing")) {
|
||||
@ -37,7 +37,7 @@ namespace TwitchChatTTS.OBS.Socket.Handlers
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Logger.LogDebug(obj.eventType + " EVENT: " + string.Join(" | ", obj.eventData?.Select(x => x.Key + "=" + x.Value?.ToString()) ?? new string[0]));
|
||||
Logger.LogDebug(obj.EventType + " EVENT: " + string.Join(" | ", obj.EventData?.Select(x => x.Key + "=" + x.Value?.ToString()) ?? new string[0]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -25,15 +25,14 @@ namespace TwitchChatTTS.OBS.Socket.Handlers
|
||||
return;
|
||||
|
||||
Logger.LogTrace("OBS websocket password: " + Context.Password);
|
||||
if (obj.authentication is null || Context.Password is null) // TODO: send re-identify message.
|
||||
if (obj.Authentication == null || Context.Password == null) // TODO: send re-identify message.
|
||||
return;
|
||||
|
||||
var salt = obj.authentication.salt;
|
||||
var challenge = obj.authentication.challenge;
|
||||
var salt = obj.Authentication.Salt;
|
||||
var challenge = obj.Authentication.Challenge;
|
||||
Logger.LogTrace("Salt: " + salt);
|
||||
Logger.LogTrace("Challenge: " + challenge);
|
||||
|
||||
|
||||
string secret = Context.Password + salt;
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(secret);
|
||||
string hash = null;
|
||||
@ -48,8 +47,7 @@ namespace TwitchChatTTS.OBS.Socket.Handlers
|
||||
}
|
||||
|
||||
Logger.LogTrace("Final hash: " + hash);
|
||||
//await sender.Send(1, new IdentifyMessage(obj.rpcVersion, hash, 1023 | 262144 | 524288));
|
||||
await sender.Send(1, new IdentifyMessage(obj.rpcVersion, hash, 1023 | 262144));
|
||||
await sender.Send(1, new IdentifyMessage(obj.RpcVersion, hash, 1023 | 262144));
|
||||
}
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ namespace TwitchChatTTS.OBS.Socket.Handlers
|
||||
return;
|
||||
|
||||
sender.Connected = true;
|
||||
Logger.LogInformation("Connected to OBS via rpc version " + obj.negotiatedRpcVersion + ".");
|
||||
Logger.LogInformation("Connected to OBS via rpc version " + obj.NegotiatedRpcVersion + ".");
|
||||
}
|
||||
}
|
||||
}
|
@ -19,13 +19,13 @@ namespace TwitchChatTTS.OBS.Socket.Handlers
|
||||
if (message is not RequestResponseMessage obj || obj == null)
|
||||
return;
|
||||
|
||||
switch (obj.requestType) {
|
||||
switch (obj.RequestType) {
|
||||
case "GetOutputStatus":
|
||||
if (sender is not OBSSocketClient client)
|
||||
return;
|
||||
|
||||
if (obj.requestId == "stream") {
|
||||
client.Live = obj.responseData["outputActive"].ToString() == "True";
|
||||
if (obj.RequestId == "stream") {
|
||||
client.Live = obj.ResponseData["outputActive"].ToString() == "True";
|
||||
Logger.LogWarning("Updated stream's live status to " + client.Live);
|
||||
}
|
||||
break;
|
||||
|
@ -10,8 +10,7 @@ namespace TwitchChatTTS.OBS.Socket.Manager
|
||||
{
|
||||
public OBSHandlerTypeManager(
|
||||
ILogger<OBSHandlerTypeManager> factory,
|
||||
[FromKeyedServices("obs")] HandlerManager<WebSocketClient,
|
||||
IWebSocketHandler> handlers
|
||||
[FromKeyedServices("obs")] HandlerManager<WebSocketClient, IWebSocketHandler> handlers
|
||||
) : base(factory, handlers)
|
||||
{
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
using TwitchChatTTS.OBS.Socket.Manager;
|
||||
using CommonSocketLibrary.Common;
|
||||
using CommonSocketLibrary.Abstract;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
Reference in New Issue
Block a user