I am getting a parsing response error using serverSentEvent. Here are my logs:
SignalR: Client subscribed to hub 'chalkhub'.
SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22chalkhub%22%7D%5D'.
SignalR: serverSentEvents transport starting.
SignalR: Attempting to connect to SSE endpoint 'https://localhost:44300/signalr/connect?transport=serverSentEvents&clientPr…%2B1Ehw%3D%3D&connectionData=%5B%7B%22name%22%3A%22chalkhub%22%7D%5D&tid=2'.
SignalR: EventSource connected.
SignalR: serverSentEvents transport connected. Initiating start request.
SignalR: The start request succeeded. Transitioning to the connected state.
SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000
SignalR: Invoking chalkhub.AddComment
SignalR: Invoked chalkhub.AddComment
SignalR error: Error: Failed at parsing response: {"C":"d-7520081E-B,2|F,0|D,0|G,1","M":[{
SignalR: Stopping connection.
SignalR: EventSource calling close().
SignalR: Fired ajax abort async = true.
SignalR: Stopping the monitoring of the keep alive.
The following is the hub connection code:
$.connection.hub.logging = true;
$.connection.hub.start().done(function() {
console.log("ding");
});
$.connection.hub.error(function(error) {
console.log('SignalR error: ' + error);
});
gAppStore.Hub.client.receivedNewComment = function(data) {
var posts = this.state.data;
var postFilter = $.grep(posts, function(p) {
return p.Id === data.PostId;
});
postFilter[0].Comments.push(data);
var newState = React.addons.update(this.state.data, {
0: {
Comments: {
$set: postFilter[0].Comments
}
}
});
console.log(posts);
this.setState({
data: posts
});
}.bind(this);
and the following hub server code:
public void AddComment(Comment comment) {
var ctx = new ApplicationDbContext();
comment.CreatedAt = DateTime.Now;
comment.UpdatedAt = DateTime.Now;
ctx.Comments.Add(comment);
ctx.SaveChanges();
Clients.All.receivedNewComment(comment);
}
and comment model:
public class Comment {
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id {
get;
set;
}
public DateTime CreatedAt {
get;
set;
}
public DateTime UpdatedAt {
get;
set;
}
[Required]
public Guid PostId {
get;
set;
}
[Required]
public string CommentByUserId {
get;
set;
}
[Required]
public string Text {
get;
set;
}
public virtual ApplicationUser CommentByUser {
get;
set;
}
public virtual Post Post {
get;
set;
}
}
After some debugging, I found that the exact error that appears on the following line in jquery.signalR-2.2.1.js :
connection.eventSource.addEventListener("message", function (e)
Exact error:
"Unexpected end to JSON input"
and the value of e.data and connection.messageId:
"{" C ":" d-7520081E-H, 1 | I, 0 | | 0 | K, 1 "," M ": [{"