-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ChatSession.onConnectionEstablished() is fired twice after invoking ChatSession.connect() #124
Comments
The code fix does not fix the described issue of CHAT_EVENTS.CONNECTION_ESTABLISHED being fired twice. There is still an event fired from the connect call, and one from LpcConnectionHelper. Perhaps this is desired behavior, but that should be noted. As it stands, onConnectionEstablished is still called twice when connect is called a single time. This is particularly interesting because when using amazon-connect-chat-interface, the duplicated call to onConnectionEstablished causes the transcript API to be called twice, which could seriously affect rate limits. |
@sseidel16 You are correct. I believe this may have been the result of a mixup. Looks like PR #196 resolved #123 instead of this issue. |
Another interesting note: The proposed fix in the initial issue is likely not feasible because, when used in conjunction with streams, the websocket can be already connected when connect is called (wsm has already connected). In that scenario, onConnectionEstablished is only called by connect, and therefore only invoked once. It seems more reasonable to only emit a connection established event after connect if the websocket has already been started (this can be seen in the response from LpcConnectionHelper start). |
…on.com/LipRAVcB7qEI/ChatJS-issues-identified-by-Marco" This reverts commit db3378506cd12b026fea45a0cd146c792025f149. cr: https://code.amazon.com/reviews/CR-87785015
Steps to reproduce:
Expected result:
The
onConnectionEstablished
listener gets invoked once:Actual result:
The
onConnectionEstablished
listener gets invoked twice with different event payloads:Analysis:
This occurs because
ChatController
actually dispatches the event twice from two different places:ChatController.prototype.connect()
call:amazon-connect-chatjs/src/core/chatController.js
Lines 192 to 201 in d85c517
amazon-connect-chatjs/src/core/chatController.js
Lines 292 to 304 in d85c517
LpcConnectionHelper.prototype.handleConnectionGain()
:amazon-connect-chatjs/src/core/chatController.js
Lines 192 to 199 in d85c517
amazon-connect-chatjs/src/core/chatController.js
Lines 207 to 218 in d85c517
amazon-connect-chatjs/src/core/chatController.js
Lines 247 to 252 in d85c517
amazon-connect-chatjs/src/core/chatController.js
Lines 288 to 290 in d85c517
Having duplicate event invocations can be problematic when the user assumes it will be invoked only once and the handler implementation is not idempotent (i.e. invoking it again may have undesired side-effects).
Proposed fix:
The event dispatch that is part of
ChatController.prototype.connect()
should be removed, so that only theLpcConnectionHelper.prototype.handleConnectionGain()
remains. This is because the latter event will be triggered whenever the connection is lost and later regained.The text was updated successfully, but these errors were encountered: