Developing with MEDKit¶
After installing MEDKit, initialize one SDK instance per extension page and wait for it to load before calling backend methods.
import Muxy from "@muxy/extensions-js";
Muxy.setup({ clientID: import.meta.env.VITE_CLIENT_ID });
const medkit = new Muxy.SDK();
await medkit.loaded();
const state = await medkit.getAllState();
console.log(state);
Choose the right API¶
| Need | API | Guide |
|---|---|---|
| Persistent extension, channel, or viewer data | State methods | Extension and viewer state |
| Broadcaster or extension settings | Config methods | Configuration data |
| Live messages between open clients | send and listen |
Simple extension |
| Large-audience counters and rankings | Aggregation methods | Data aggregation |
| Local Twitch identity/role simulation | DebuggingOptions |
User simulation |
| Twitch Helix helpers | TwitchClient |
Twitch API |
State is durable; a live message is not. For interfaces that must recover after refresh, persist the latest value first and then send a message to active clients.
Handle failures explicitly¶
MEDKit methods return promises. Surface initialization and request failures in both logs and the UI, and never assume a write succeeded before its promise resolves.
try {
await medkit.setChannelState({ round: 4 });
status.textContent = "Saved";
} catch (error) {
console.error(error);
status.textContent = "Save failed";
}
See Troubleshooting for environment, role, and token checks.