namespace WebsocketServer.Services
{
[Service]
public interface IWebsocketServer
{
void SendMessage(string message);
}
[PluginServiceImplementation(Lifetime = ServiceLifetime.Singleton, Priority = Priority.Lowest)]
public class WebsocketServerService : IWebsocketServer, IDisposable
{
private readonly WebSocketServer m_WebSocketServer;
private readonly WebSocketService m_WebSocketService;
public WebsocketServerService()
{
m_WebSocketServer = new WebSocketServer(27015);
m_WebSocketService = new WebSocketService();
m_WebSocketServer.AddWebSocketService
<WebSocketService>("/playerinfo");
m_WebSocketServer.Start();
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
m_WebSocketServer?.Stop();
}
}
public void SendMessage(string message)
{
Console.WriteLine("asd");
m_WebSocketService.Send(message);
}
}
}