refactor(thread): refactor hasCapability call with a better readable way #3732
+213
−87
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Update
LIST_CAPABILITY has been deprecated and will no longer be used.
Description
In the new version, we will no longer use hasCapability individually to check exposed APIs. Instead, we will obtain them during the communication establishment between two threads. Here we provide 1 protocol change and 2 inner thread methods.
Protocol Change
Added a mechanism to exchange exposed APIs. When data is received, it will be automatically saved to cache.
Inner Thread Methods
Clarification: 'A' represents Outside (the IDE/client), while 'B' represents Inside (the server).
In our scenario, A is always created first, followed by B. This ensures B can successfully send messages to A. However, if A arrives too early, B might not receive the message signal. Furthermore, we only need A's Exposed APIs on the B side (server side). Currently, we only use requestMethods in
createThreadFromInsideIframe
.By the way, we could also use exposed methods to check server's exposed APIs?
I have added numerous logs for now, which will be cleaned up after review.
Demo
Screenshot from log
Also the way we call in server side