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
9 changed files
with
53 additions
and
50 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
8 changes: 4 additions & 4 deletions
8
Demo.AspNetCore.WebSockets/Infrastructure/ITextWebSocketSubprotocol.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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Net.WebSockets; | ||
using Lib.AspNetCore.WebSocketsCompression.Providers; | ||
|
||
namespace Demo.AspNetCore.WebSockets.Infrastructure | ||
{ | ||
public interface ITextWebSocketSubprotocol | ||
{ | ||
string SubProtocol { get; } | ||
|
||
Task SendAsync(string message, WebSocket webSocket, CancellationToken cancellationToken); | ||
Task SendAsync(string message, WebSocket webSocket, IWebSocketCompressionProvider webSocketCompressionProvider, CancellationToken cancellationToken); | ||
|
||
string Read(byte[] bytes); | ||
string Read(string rawMessage); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
Demo.AspNetCore.WebSockets/Infrastructure/JsonWebSocketSubprotocol.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 |
---|---|---|
@@ -1,21 +1,21 @@ | ||
using System; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Net.WebSockets; | ||
using Newtonsoft.Json; | ||
using Lib.AspNetCore.WebSocketsCompression.Providers; | ||
|
||
namespace Demo.AspNetCore.WebSockets.Infrastructure | ||
{ | ||
public class JsonWebSocketSubprotocol : TextWebSocketSubprotocolBase, ITextWebSocketSubprotocol | ||
{ | ||
public string SubProtocol => "aspnetcore-ws.json"; | ||
|
||
public override Task SendAsync(string message, WebSocket webSocket, CancellationToken cancellationToken) | ||
public override Task SendAsync(string message, WebSocket webSocket, IWebSocketCompressionProvider webSocketCompressionProvider, CancellationToken cancellationToken) | ||
{ | ||
string jsonMessage = JsonConvert.SerializeObject(new { message, timestamp = DateTime.UtcNow }); | ||
|
||
return base.SendAsync(jsonMessage, webSocket, cancellationToken); | ||
return base.SendAsync(jsonMessage, webSocket, webSocketCompressionProvider, cancellationToken); | ||
} | ||
} | ||
} |
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
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