Accept an external instance (v1.3.0) - #13
Merged
Merged
Conversation
Owner
Author
|
I can make the user parameter nullable to make authentication optional. However, it's important to note that if the user isn't authenticated, while the Unity game would load anyway, any attempt to communicate with the Discord client will result in an error. |
Owner
Author
|
Using an external instance without authentication would be something like this:
import { useSdk, DiscordSDK, DataPromise } from "dissonity";
let authenticate = /* Authenticate? */;
window.addEventListener("DOMContentLoaded", async () => {
const promise: DataPromise = new Promise(async resolve => {
const discordSdk = new DiscordSDK(/* Client id */);
await discordSdk.ready();
if (authenticate) {
// (Authorization process...)
const { user } = await discordSdk.commands.authenticate({
access_token: /* Retrieved access token */,
});
resolve({ discordSdk, user });
}
else {
resolve({ discordSdk, user: null });
}
});
useSdk(promise);
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request adds support for using an external SDK instance to improve compatibility with the Robo.js framework.
New exports
DiscordSDK: classuseSdk: functionDataPromise: typeExplanation
Dissonity v1 needs to have an instance and a user object to provide functionality. By the time the Unity build loads, the message handler has to be already awaiting the data. If
useSdkwas called once the authentication was done (and you had access to the user object), messages sent by Unity until then would be lost.This is avoided by passing a promise to
useSdkthat will resolve once authentication is done. That way, messages sent by Unity before authentication are left pending until the promise is resolved.The
DataPromisetype represents the shape this promise needs to have.Use
index.tsTODO