Basic Websocket support working, without authentication (auth broken)

This commit is contained in:
Alexander Horner
2022-12-07 21:36:03 +00:00
parent fe4ae354b2
commit 1e1187e71f
5 changed files with 286 additions and 94 deletions

View File

@@ -34,8 +34,15 @@ namespace ntfysh_client
if (result != DialogResult.OK) return;
//Subscribe
_notificationListener.SubscribeToTopicUsingLongHttpJson(dialog.Unique, dialog.TopicId, dialog.ServerUrl, dialog.Username, dialog.Password);
if (dialog.UseWebsockets)
{
_notificationListener.SubscribeToTopicUsingWebsocket(dialog.Unique, dialog.TopicId, dialog.ServerUrl, dialog.Username, dialog.Password);
}
else
{
_notificationListener.SubscribeToTopicUsingLongHttpJson(dialog.Unique, dialog.TopicId, dialog.ServerUrl, dialog.Username, dialog.Password);
}
//Add to the user visible list
notificationTopics.Items.Add(dialog.Unique);
@@ -167,7 +174,24 @@ namespace ntfysh_client
//Load them in
foreach (SubscribedTopic topic in topics)
{
_notificationListener.SubscribeToTopicUsingLongHttpJson($"{topic.TopicId}@{topic.ServerUrl}", topic.TopicId, topic.ServerUrl, topic.Username, topic.Password);
string[] parts = topic.ServerUrl.Split("://", 2);
switch (parts[0].ToLower())
{
case "ws":
case "wss":
_notificationListener.SubscribeToTopicUsingWebsocket($"{topic.TopicId}@{topic.ServerUrl}", topic.TopicId, topic.ServerUrl, topic.Username, topic.Password);
break;
case "http":
case "https":
_notificationListener.SubscribeToTopicUsingLongHttpJson($"{topic.TopicId}@{topic.ServerUrl}", topic.TopicId, topic.ServerUrl, topic.Username, topic.Password);
break;
default:
continue;
}
notificationTopics.Items.Add($"{topic.TopicId}@{topic.ServerUrl}");
}
}