更新记录
1.3.5(2021-12-03)
更新文档,新增链接失败,断开重试示例
1.3.4(2021-12-03)
更新文档
1.3.3(2021-12-02)
更新文档,新增链接失败,断开重试示例
查看更多
平台兼容性
HbuilderX/cli最低兼容版本 |
3.0.7 |
uni-app
app-vue |
app-nvue |
app-android |
app-ios |
? |
? |
? |
? |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
? |
? |
? |
? |
? |
? |
? |
? |
? |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
? |
? |
? |
? |
? |
? |
? |
? |
? |
uni-app x
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
? |
? |
? |
? |
? |
? |
? |
? |
? |
Lyuan-SignalR
使用方法与官方文档一致,请自行参考官方文档
兼容微信小程序、h5、Android、ios ,其他小程序未测, 理论支持。
断线重连、重试等功能需自行判断,该库修改自微软官方。
import {
HubConnectionBuilder,
LogLevel
} from './signalr.js';
const connection = new HubConnectionBuilder()
.withUrl("http://xxx.com/messagehub", {
// accessTokenFactory: () => {
// return 'token';
// }
})
.configureLogging(LogLevel.Trace)
.build();
//接收消息
connection.on("ReceiveMessage", function (user, message) {
console.log("收到的消息");
});
//发送消息, 需在链接成功后调用
//connection.invoke('方法名',参数)
//链接断开
connection.on/close(function () { //去掉斜杠
console.log("websocket连接断开");
//重试
start(ms);
});
const ms = 5000;
const start = (timer) => {
setTimeout(() => {
try {
connection
.start()
.then(() => {
console.log("websocket连接成功!");
})
.catch((e) => {
//重试
console.log("websocket连接失败", e);
start(ms);
});
} catch (e) {
//重试
start(ms);
}
}, timer);
};
//开始连接
start(0);
觉得有用的话,可直接打赏或微信(付费咨询)