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

Update url param to be dynamic if needed #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Gabiras12
Copy link

As requested by issue #59 my use case is the same. I need to pass a token on every connection attempt and it's only possible to use the token once. So the url must change on every reconnect attempt.

If url param is a function invoke it passing the attempt number

Solution:
Change the url param to be of type:

- string
- Promise<string>
- (attempt: number) => Promise<string>
- (attempt: number) => string

So the usage would look like:

// string as it is now
new Sockette('wss://address')
// promise style. just adding the setTimeout to simulate
new Sockette(new Promise((resolve) => {
  setTimeout(() => {
    resolve('wss://address')
  }, 5000)
}))

new Sockette(Promise.resolve('wss://address'))

new Sockette((attempt) => `wss://address?attempt${attempt}`)

new Sockette(async (attempt) => await Promise.resolve(`wss://address?attempt${attempt}`))

@Gabiras12
Copy link
Author

@lukeed can we have this merged?

@ghost
Copy link

ghost commented Jul 10, 2021

+1 to @Gabiras12
@lukeed let us know if this PR could be merged and released.

@exaucae
Copy link

exaucae commented Oct 31, 2021

bump!

@Gabiras12
Copy link
Author

@ghost and @exaucae I've published this PR under sockette-dynamic-url
https://www.npmjs.com/package/sockette-dynamic-url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants