Skip to content
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

feat: fetch gateway information without requiring rest in ws #10651

Merged
merged 8 commits into from
Jan 13, 2025

Conversation

vladfrangu
Copy link
Member

Please describe the changes this PR makes and why it should be merged:

Currently the only way to override the gateway URL that /ws will connect to is by intercepting the rest request and overriding it. This PR lets you pick a different ws url, if you may be proxying it or have custom implementations or what not.

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • This PR changes the library's interface (methods or parameters added)

@vladfrangu vladfrangu requested a review from a team as a code owner December 9, 2024 17:42
@vladfrangu vladfrangu requested review from iCrawl and didinele December 9, 2024 17:42
Copy link

vercel bot commented Dec 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
discord-js ⬜️ Ignored (Inspect) Visit Preview Jan 13, 2025 10:21am
discord-js-guide ⬜️ Ignored (Inspect) Visit Preview Jan 13, 2025 10:21am

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 64.70588% with 6 lines in your changes missing coverage. Please review.

Project coverage is 37.29%. Comparing base (ae0265e) to head (03ca1d6).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
packages/ws/src/ws/WebSocketManager.ts 62.50% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10651      +/-   ##
==========================================
- Coverage   38.00%   37.29%   -0.71%     
==========================================
  Files         239      239              
  Lines       14884    15164     +280     
  Branches     1385     1386       +1     
==========================================
- Hits         5657     5656       -1     
- Misses       9216     9496     +280     
- Partials       11       12       +1     
Flag Coverage Δ
ws 34.68% <64.70%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@didinele didinele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Just one classic mistake I've made a few times too, callbacks aren't encodeable over worker_threads, so this needs updating, otherwise we get hard crashes:

export interface FetchingStrategyOptions
extends Omit<
WebSocketManagerOptions,
| 'buildIdentifyThrottler'
| 'buildStrategy'
| 'rest'
| 'retrieveSessionInfo'
| 'shardCount'
| 'shardIds'
| 'updateSessionInfo'
> {
readonly gatewayInformation: APIGatewayBotInfo;
readonly shardCount: number;
}

Along with its runtime counter-part:

export async function managerToFetchingStrategyOptions(manager: WebSocketManager): Promise<FetchingStrategyOptions> {
const {
buildIdentifyThrottler,
buildStrategy,
retrieveSessionInfo,
updateSessionInfo,
shardCount,
shardIds,
rest,
...managerOptions
} = manager.options;
return {
...managerOptions,
token: manager.token,
gatewayInformation: await manager.fetchGatewayInformation(),
shardCount: await manager.getShardCount(),
};
}

In the future I'll probably rewrite this to a Pick 😅

@Jiralite Jiralite added this to the ws 2.1.0 milestone Dec 9, 2024
almeidx
almeidx previously requested changes Dec 9, 2024
Copy link
Member

@almeidx almeidx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the README and tests need updating

packages/ws/src/ws/WebSocketManager.ts Outdated Show resolved Hide resolved
@vladfrangu vladfrangu changed the title feat: overridable initial gateway URL feat: fetch gateway information without requiring rest in ws Dec 9, 2024
@didinele
Copy link
Member

this needs a rebase now

@vladfrangu vladfrangu force-pushed the feat/custom-gateway-url-support branch from 89c2b68 to 2626c9a Compare December 14, 2024 20:58
@kodiakhq kodiakhq bot merged commit 5f7d335 into main Jan 13, 2025
8 checks passed
@kodiakhq kodiakhq bot deleted the feat/custom-gateway-url-support branch January 13, 2025 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants