microsoft / microsoft/BotFramework-DirectLineJS
Connection status Online when Websockets connection failing
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- TypeScript
- Star
- 199
- Fork
- 133
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
We are using this library in our React app and I encounter this weird behaviour.
The problem
When disabled Websockets connection in Chrome browser using these steps:
- Open Chrome and install this extension
- Restart Chrome
- Go to the Extensions
- Click uBlock Origin, the dashboard window or popup should be viewed
- From the dashboard, click on Settings (cogs icon, see image above)
- In the settings go to My filters tab
- Add
||*^$websocketto 1st line of the filter editor and hit Apply changes
I can see that it successfully blocks the wss connections as I can see failed requests in my network tab. The problem is that the connection status will eventually set to ConnectionStatus.Online. I would expect that it will be ConnectionStatus.FailedToConnect as the Websockets request are failing. We need this so we can react with our UI to this scenario and also to log this to our internal logging systems. I cannot see how to do it without proper connection status information, though.
Our setup
In the React code we are just initializing my DirectLine instance in effect hook:
useEffect(() => {
if (directLineTokenData) {
const body = {
token: directLineTokenData.token || '',
conversationId: conversationId || '',
...COMMON_BOT_PROPERTIES,
};
setDirectLine(new DirectLine(body));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [directLineTokenData]);
and in another we subscribe to the activity$ and connectionStatus$ observables:
useEffect(() => {
// eslint-disable-next-line no-console
console.log('Starting subscription to all activities');
const subscribtion = directLine?.activity$.subscribe(activity =>
// eslint-disable-next-line no-console
console.log('Received activity:', activity),
);
// eslint-disable-next-line no-console
const connectionStatusSubscription = directLine?.connectionStatus$.subscribe(
status => {
switch (status) {
case ConnectionStatus.Uninitialized:
// eslint-disable-next-line no-console
console.log('STATUS: uninitialized');
break;
case ConnectionStatus.Connecting:
// eslint-disable-next-line no-console
console.log('STATUS: connecting...');
break;
case ConnectionStatus.Online:
// eslint-disable-next-line no-console
console.log('STATUS: online');
break;
case ConnectionStatus.ExpiredToken:
// eslint-disable-next-line no-console
console.log('STATUS: expired token');
break;
case ConnectionStatus.FailedToConnect:
// eslint-disable-next-line no-console
console.log('STATUS: failed to connect');
break;
case ConnectionStatus.Ended:
// eslint-disable-next-line no-console
console.log('STATUS: ended');
break;
default:
// eslint-disable-next-line no-console
console.log('STATUS: unknown status', status);
}
},
error => {
// eslint-disable-next-line no-console
console.error('Error subscribing to connection status', error);
},
);
return () => {
console.log('Stopping subscription to all activities');
subscribtion?.unsubscribe();
connectionStatusSubscription?.unsubscribe();
};
}, [directLine]);
Observing the problem
Console logs from our React app:
From the logs we can see that there is eventually a ConnectionStatus.Online connection status change, even though failing Websockets requests. What's interesting that it sets connection status to ConnectionStatus.FailedToConnect one time (before it is set to ConnectionStatus.Online)
Any help is appreciated 🙏
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện vấn đề trong thiết lập React bằng cách chặn các yêu cầu WebSocket với bộ lọc uBlock Origin đã được ghi lại, sau đó quan sát connectionStatus$ của DirectLine cùng với activity$. Bắt đầu bằng cách lần theo vòng đời của constructor DirectLine và connectionStatus$; hoàn thành khi một kết nối wss liên tục thất bại báo cáo ConnectionStatus.FailedToConnect thay vì cuối cùng trở thành Online.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- react, typescript
- Lĩnh vực
- api, networking
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 30/100