当你需要ChatAI服务但无法魔法或没有海外手机号码时,Chat8就是你的解决方案。我们基于OpenAi开发,所有用户内容都会加密,欢迎使用!点击使用:
https://chat.chat826.com/#/register?bronk_on=375671
源码
https://gitee.com/zzbbc/samplewebsocketsignalr
1,引入 SignalR
services.AddSignalR();
2,路由设置
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<VideoHub>("/videohub"); // 配置VideoHub
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
3,创建signalR服务
public class VideoHub : Microsoft.AspNetCore.SignalR.Hub
{
public async Task SendBitmap(byte[] bytes)
{
// 将视频帧发送给所有连接的客户端
await Clients.All.SendAsync("ReceiveVideoFrame", bytes);
}
/// <summary>
/// 收到信息
/// </summary>
/// <returns></returns>
[HubMethodName("SendMessage")]
public async Task SendMessage(string message)
{
var bs= Encoding.UTF8.GetBytes(message);
SendBitmap(bs);
}
/// <summary>
/// 连接时
/// </summary>
/// <returns></returns>
public override Task OnConnectedAsync()
{
return base.OnConnectedAsync();
}
/// <summary>
/// 断开时
/// </summary>
/// <param name="exception"></param>
/// <returns></returns>
public override Task OnDisconnectedAsync(Exception exception)
{
return base.OnDisconnectedAsync(exception);
}
}
4 h5 前端
<script src="~/js/signalr.js"></script> //自己找
<script type="text/javascript">
let connection = new signalR.HubConnectionBuilder().withUrl("/videohub").build();
connection.on("ReceiveVideoFrame", function (bytes) {
//收到信息
});
connection.start().then(function() {
console.log('signalR连接成功');
//发消息给服务端
const message = "Hello from client!";
connection.invoke("SendMessage", message);
}).catch(function(err) {
console.error(err.toString());
});
</script>