Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

42 rindas
1.2 KiB

  1. using System;
  2. using System.Net.WebSockets;
  3. using System.Threading.Tasks;
  4. using MQTTnet.Adapter;
  5. using MQTTnet.Diagnostics;
  6. using MQTTnet.Serializer;
  7. using MQTTnet.Server;
  8. namespace MQTTnet.AspNetCore
  9. {
  10. public sealed class MqttWebSocketServerAdapter : IMqttServerAdapter, IDisposable
  11. {
  12. public event EventHandler<MqttServerAdapterClientAcceptedEventArgs> ClientAccepted;
  13. public Task StartAsync(IMqttServerOptions options)
  14. {
  15. return Task.CompletedTask;
  16. }
  17. public Task StopAsync()
  18. {
  19. return Task.CompletedTask;
  20. }
  21. public Task AcceptWebSocketAsync(WebSocket webSocket)
  22. {
  23. if (webSocket == null) throw new ArgumentNullException(nameof(webSocket));
  24. var channel = new MqttWebSocketServerChannel(webSocket);
  25. var clientAdapter = new MqttChannelAdapter(channel, new MqttPacketSerializer(), new MqttNetLogger());
  26. var eventArgs = new MqttServerAdapterClientAcceptedEventArgs(clientAdapter);
  27. ClientAccepted?.Invoke(this, eventArgs);
  28. return eventArgs.SessionTask;
  29. }
  30. public void Dispose()
  31. {
  32. StopAsync();
  33. }
  34. }
  35. }