-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
219 additions
and
138 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
60 changes: 60 additions & 0 deletions
60
Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerChannel.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,60 @@ | ||
using System; | ||
using System.IO; | ||
using System.Net.WebSockets; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MQTTnet.Core.Channel; | ||
using MQTTnet.Implementations; | ||
|
||
namespace MQTTnet.AspNetCore | ||
{ | ||
public class MqttWebSocketServerChannel : IMqttCommunicationChannel, IDisposable | ||
{ | ||
private WebSocket _webSocket; | ||
|
||
public MqttWebSocketServerChannel(WebSocket webSocket) | ||
{ | ||
_webSocket = webSocket ?? throw new ArgumentNullException(nameof(webSocket)); | ||
|
||
SendStream = new WebSocketStream(_webSocket); | ||
ReceiveStream = SendStream; | ||
} | ||
|
||
public Stream SendStream { get; private set; } | ||
public Stream ReceiveStream { get; private set; } | ||
|
||
public Task ConnectAsync() | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
public async Task DisconnectAsync() | ||
{ | ||
if (_webSocket == null) | ||
{ | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
await _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None); | ||
} | ||
finally | ||
{ | ||
Dispose(); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
SendStream?.Dispose(); | ||
ReceiveStream?.Dispose(); | ||
|
||
_webSocket?.Dispose(); | ||
|
||
SendStream = null; | ||
ReceiveStream = null; | ||
_webSocket = null; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.