danielwerg / r6api.js

🍫 Node.js wrapper around Rainbow Six Siege APIs
https://npm.im/r6api.js
MIT License
111 stars 19 forks source link

Cannot use multiple instances of R6API #71

Open BadCoder1337 opened 3 years ago

BadCoder1337 commented 3 years ago

I need to create a different session with non-default Ubi-AppId to interact with another domain of endpoints. Example code:

const friendsApi = new R6API(credentials)
const chatApi = new R6API({ ...credentials, ubiAppId: OVERLAY_APP_ID })

const friendsApiAuth = await friendsApi.getAuth()
const chatApiAuth = await chatApi.getAuth()
console.log(friendsApiAuth, chatApiAuth)

But because of global variables in auth.ts and other places I cannot construct 2nd R6API instance. getAuth from both instances gives the same object which is impossible since session endpoint is non-idempotent.

danielwerg commented 3 years ago

You can call setAuthFileName method before you need to change ubi app id, it's non-ideal solution but a workaround.

const friendsApi = new R6API(credentials)
- const chatApi = new R6API({ ...credentials, ubiAppId: OVERLAY_APP_ID })
+ const chatApi = new R6API(credentials)

+ const defaultAppId = '3587dcbb-7f81-457c-9781-0e3f29f6f56a';
+ const altAppId = '83564d31-7cd7-4bc0-a763-6524e78d1a7f';

+ friendsApi.setAuthFileName(`r6api.js-auth-${defaultAppId}`);
const friendsApiAuth = await friendsApi.getAuth()
+ chatApi.setAuthFileName(`r6api.js-auth-${altAppId}`);
const chatApiAuth = await chatApi.getAuth()
console.log(friendsApiAuth, chatApiAuth)
danielwerg commented 3 years ago

@BadCoder1337 did example above resolve your issue?

BadCoder1337 commented 3 years ago

I split code into separate workers. It's easier for me than creating and loading JSON. But the issue is still relevant as a refactor goal.