microsoft / microsoft/BotFramework-DirectLineJS
Connection status Online when Websockets connection failing
还没有人认领这个 Issue。
- 主要语言
- TypeScript
- 星标
- 199
- 派生
- 133
- PR 合并指标
- 30 天内没有已合并 PR
描述
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 🙏
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
通过使用文档中说明的 uBlock Origin 过滤器阻止 WebSocket 请求,在 React 设置中复现该问题,然后观察 DirectLine 的 connectionStatus$ 以及 activity$。首先跟踪 DirectLine 构造函数和 connectionStatus$ 的生命周期;当持续失败的 wss 连接报告 ConnectionStatus.FailedToConnect,而不是最终变为 Online 时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- react, typescript
- 领域
- api, networking
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 30/100