conficient / blazorchatsample Goto Github PK
View Code? Open in Web Editor NEWA sample Blazor chat application using SignalR
A sample Blazor chat application using SignalR
Hi
You demo is awesome: really tnx.
Just a stupid question: what is the purpose of connections lookup object in chatClient.js ?
We can have only 1 connection in this sample.
Why not use a simple object ?
Tnx
A few issues to fix:
xs
view modeClient should send a message "{user} joined the chat" on connecting, and "{user} left the chat" on disconnecting.
I did try to implement this in the original version, but had SignalR errors. I suspect the chat connecting had not completed when connecting (I think the .start()
method may return a promise?).
The project cannot be opened in visual studio and when i try to run with dotnet run i get this error that only happens with this application:
Found .NET Core SDK, but did not find dotnet.dll at [C:\Program Files\dotnet\sdk\3.1.100\dotnet.dll]
At present the Start(), Send() and Stop() methods are all synchronous, but it's likely the underlying js methods are async, returning promises.
Need to rewrite ChatClient
to be async and amend chatClient.js
to match.
Server is refusing websocket connections for SignalR, using SSE instead.
Upgrade to latest .NET Core 3 preview:
https://devblogs.microsoft.com/aspnet/asp-net-core-and-blazor-updates-in-net-core-3-0-preview-6/
The text <code>invokeAsync<object></code>
gets rendered as <code>invokeAsync <object></object>
on the Index page
Known bug in current mono WASM release:
mono/mono#18628
This has now been fixed but we are awaiting the next Blazor/WASM release.
I have blazor sample working, and can start chats etc, but I am wanting to connect a console app to the same chat hub on the same pc, but cannot.
Here is the sample code
` private static void Main(string[] args)
{
Console.WriteLine("Starting App...");
//Set connection
//var connection = new HubConnection("http://127.0.0.1:6836/");
var connection = new HubConnection("http://localhost:6836");
//Make proxy to hub based on hub name on server
var myHub = connection.CreateHubProxy("/ChatHub");
//Start connection
Console.WriteLine("Starting Connection");
for (int i = 0; i < 5; i++)
{
Console.WriteLine("Sleeping...");
Thread.Sleep(1000);
}
myHub.On<string>("addMessage", param => {
Console.WriteLine(param);
});
connection.Start().ContinueWith(task => {
if (task.IsFaulted)
{
Console.WriteLine("There was an error opening the connection:{0}",
task.Exception.GetBaseException());
}
else
{
Console.WriteLine("Connected");
}
}).Wait();
for (int i = 0; i < 5;i++)
{
Console.WriteLine("Sleeping...");
Thread.Sleep(1000);
}
myHub.Invoke<string>("Send", "HELLO World ").ContinueWith(task => {
if (task.IsFaulted)
{
Console.WriteLine("There was an error calling send: {0}",
task.Exception.GetBaseException());
}
else
{
Console.WriteLine(task.Result);
}
});
`
The error is
There was an error opening the connection:Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: ?. Path '', line 0, position 0.
at Newtonsoft.Json.JsonTextReader.ParseValue()
at Newtonsoft.Json.JsonTextReader.ReadInternal()
at Newtonsoft.Json.JsonTextReader.Read()
at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader)
at Newtonsoft.Json.Linq.JObject.Parse(String json)
at Microsoft.AspNet.SignalR.Client.Transports.TransportHelper.<>c.b__0_1(String raw) in //src/Microsoft.AspNet.SignalR.Client/Transports/TransportHelper.cs:line 43
at Microsoft.AspNet.SignalR.TaskAsyncHelper.<>c__DisplayClass31_02.<Then>b__0(Task
1 t) in //src/Microsoft.AspNet.SignalR.Core/TaskAsyncHelper.cs:line 494
at Microsoft.AspNet.SignalR.TaskAsyncHelper.TaskRunners2.<>c__DisplayClass3_0.<RunTask>b__0(Task
1 t) in /_/src/Microsoft.AspNet.SignalR.Core/TaskAsyncHelper.cs:line 1280
Any clues as to what I am doing wrong ?
as I understand it this is a public chat, where anyone who enters talks with everyone. don't have a way to make a hub between two people only?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.