parent
6ed3f6d1aa
commit
4db78685dc
|
|
@ -35,15 +35,15 @@ connection.on('SetUsersOnline', usersOnline => {
|
|||
|
||||
connection.on('UsersJoined', users => {
|
||||
users.forEach(user => {
|
||||
appendLine('User ' + user.Name + ' joined the chat');
|
||||
appendLine('User ' + user.name + ' joined the chat');
|
||||
addUserOnline(user);
|
||||
});
|
||||
});
|
||||
|
||||
connection.on('UsersLeft', users => {
|
||||
users.forEach(user => {
|
||||
appendLine('User ' + user.Name + ' left the chat');
|
||||
document.getElementById(user.ConnectionId).outerHTML = '';
|
||||
appendLine('User ' + user.name + ' left the chat');
|
||||
document.getElementById(user.connectionId).outerHTML = '';
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -78,12 +78,12 @@ function appendLine(line, color) {
|
|||
};
|
||||
|
||||
function addUserOnline(user) {
|
||||
if (document.getElementById(user.ConnectionId)) {
|
||||
if (document.getElementById(user.connectionId)) {
|
||||
return;
|
||||
}
|
||||
var userLi = document.createElement('li');
|
||||
userLi.innerText = `${user.Name} (${user.ConnectionId})`;
|
||||
userLi.id = user.ConnectionId;
|
||||
userLi.innerText = `${user.name} (${user.connectionId})`;
|
||||
userLi.id = user.connectionId;
|
||||
document.getElementById('users').appendChild(userLi);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using System.IO;
|
|||
using Microsoft.AspNetCore.SignalR.Internal.Formatters;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
|
||||
{
|
||||
|
|
@ -34,7 +35,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
|
|||
/// NOT be changed using this serializer.
|
||||
/// </summary>
|
||||
public JsonHubProtocol()
|
||||
: this(new JsonSerializer())
|
||||
: this(JsonSerializer.Create(CreateDefaultSerializerSettings()))
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -258,5 +259,10 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
|
|||
return new CompletionMessage(invocationId, error, result: payload, hasResult: true);
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonSerializerSettings CreateDefaultSerializerSettings()
|
||||
{
|
||||
return new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.SignalR
|
|||
{
|
||||
public class HubOptions
|
||||
{
|
||||
public JsonSerializerSettings JsonSerializerSettings { get; set; } = new JsonSerializerSettings();
|
||||
public JsonSerializerSettings JsonSerializerSettings { get; set; } = JsonHubProtocol.CreateDefaultSerializerSettings();
|
||||
public SerializationContext MessagePackSerializationContext { get; set; } = MessagePackHubProtocol.CreateDefaultSerializationContext();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1008,7 +1008,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
{
|
||||
o.JsonSerializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
ContractResolver = new DefaultContractResolver()
|
||||
};
|
||||
});
|
||||
});
|
||||
|
|
@ -1026,7 +1026,34 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
var message = (InvocationMessage)await client.ReadAsync().OrTimeout();
|
||||
|
||||
var customItem = message.Arguments[0].ToString();
|
||||
// Originally "Message" and "paramName"
|
||||
// by default properties serialized by JsonHubProtocol are using camelCasing
|
||||
Assert.Contains("Message", customItem);
|
||||
Assert.Contains("paramName", customItem);
|
||||
|
||||
client.Dispose();
|
||||
|
||||
await endPointLifetime.OrTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task JsonHubProtocolUsesCamelCasingByDefault()
|
||||
{
|
||||
var serviceProvider = CreateServiceProvider();
|
||||
var endPoint = serviceProvider.GetService<HubEndPoint<MethodHub>>();
|
||||
|
||||
using (var client = new TestClient())
|
||||
{
|
||||
var endPointLifetime = endPoint.OnConnectedAsync(client.Connection);
|
||||
|
||||
await client.Connected.OrTimeout();
|
||||
|
||||
await client.SendInvocationAsync(nameof(MethodHub.BroadcastItem)).OrTimeout();
|
||||
|
||||
var message = (InvocationMessage)await client.ReadAsync().OrTimeout();
|
||||
|
||||
var customItem = message.Arguments[0].ToString();
|
||||
// originally Message, paramName
|
||||
Assert.Contains("message", customItem);
|
||||
Assert.Contains("paramName", customItem);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue