【发布时间】:2019-10-18 19:22:53
【问题描述】:
连接到服务器时,我不断收到 Failed to start the transport 'WebSockets': null 。
我正在响应式移动应用中实现一个简单的聊天。我正在使用@aspnet/signalr(version-1.1.4) 库。我收到此错误 - 错误:无法启动传输“WebSockets”:null。 在此处查看日志
componentDidMount(){
try {
const connection = new signalR.HubConnectionBuilder() //Connect to a hub
.withUrl(baseUrl + `/chatbus`, {
transport: signalR.HttpTransportType.WebSockets | signalR.HttpTransportType.LongPolling,
'content-type': 'application/json',
accessTokenFactory: () => authToken //for authorization
})
.configureLogging(signalR.LogLevel.Debug)
.build();
connection.on('NotifySignalR', (ChatObject) => {
console.log(ChatObject);
});
connection.start()
.then(() => {
console.log('Chat Connection started.');
console.log('Now connected, connection ID=' + connection.id);
this.initalAttemptForChat = true;
connection.invoke("start");
})
.catch(() => {
this.initalAttemptForChat = false;
console.log('Error while establishing chatbus connection!');
});
} catch (e) {
console.log("error ", e);
throw e;
}
}
【问题讨论】:
标签: react-native signalr