|
| 1 | +--- |
| 2 | +title: Extension Integration |
| 3 | +--- |
| 4 | + |
| 5 | +# Extension Integration |
| 6 | + |
| 7 | +Extensions can do many things, however PenguinMod doesn't actually have many ways to access the insides of your extension. |
| 8 | +This causes buggy or broken behavior in cases like Audio extensions not working with the pause button, volume slider, and project recorder addons. |
| 9 | + |
| 10 | +The [`registerExtensionIntegrationComponents`](#registerextensionintegrationcomponents) function is intended to help with this. |
| 11 | + |
| 12 | +## registerExtensionIntegrationComponents |
| 13 | +```js |
| 14 | +Scratch.vm.runtime.registerExtensionIntegrationComponents(extensionId, whitelistFeatures, components); |
| 15 | +``` |
| 16 | + |
| 17 | +This function allows extensions to register components that are used for other PenguinMod features. |
| 18 | +This can include GUI menus, addons, or other extensions. |
| 19 | + |
| 20 | +You can re-run this function if you need to change any information. |
| 21 | +However, the original information will be replaced, not appended to. |
| 22 | + |
| 23 | +|Parameter|Type|Explanation| |
| 24 | +|:-:|:-:|:-:| |
| 25 | +|`extensionId`|`string`|The ID of your extension. Should be the same ID your extension already uses elsewhere.| |
| 26 | +|`whitelistFeatures`|`Array<string>`|Which features to enable. See [`whitelistFeatures`](#whitelistfeatures).| |
| 27 | +|`components`|`object`|Parts of your extension. See [`components`](#components).| |
| 28 | + |
| 29 | +### `whitelistFeatures` |
| 30 | +This is a list of permissions which determines what PenguinMod can do with the provided components. Passing an empty array will allow all components provided to be used by PenguinMod's features. |
| 31 | + |
| 32 | +Generally you should use an empty array and not heavily use the components you provide, but some extensions might want to manually make support for some PenguinMod features to be in control of their behavior. |
| 33 | + |
| 34 | +Only some components are used by each permission. You don't have to provide the components attached to a permission, but when using the whitelist, it's pointless to specify a permission that you won't provide the components for. |
| 35 | +This is an array of strings. If you want to use the whitelist, the array can contain any of these permissions: |
| 36 | + |
| 37 | +|Permission|Components|Explanation| |
| 38 | +|:-:|:-:|:-:| |
| 39 | +|`audioContextSuspend`|`audioContexts`|Allows PenguinMod to run `AudioContext.suspend()` on your `AudioContext`s| |
| 40 | +|`audioContextResume`|`audioContexts`|Allows PenguinMod to run `AudioContext.resume()` on your `AudioContext`s| |
| 41 | +|`audioMediaStream`|`audioContexts`, `audioNodes`|Allows PenguinMod to create media stream destinations and connect the `AudioNode`s to them| |
| 42 | +|`gainNodeSet`|`gainNodes`|Allows PenguinMod to set the `gain.value` on your `GainNode`s| |
| 43 | + |
| 44 | +### `components` |
| 45 | +This is an object containing all of the components of your extension that you want to make work with PenguinMod's features. |
| 46 | + |
| 47 | +|Key|Value|Explanation| |
| 48 | +|:-:|:-:|:-:| |
| 49 | +|`audioContexts`|`Array<AudioContext>`|Any `AudioContext`s being used in the extension that you want to register.| |
| 50 | +|`audioNodes`|`Array<AudioNode>`|Any destination `AudioNode`s you want to register, however see [`audioNodes`](#audionodes) to provide these properly.| |
| 51 | +|`gainNodes`|`Array<GainNode>`|The deepest `GainNode`s you want to register, see [`gainNodes`](#gainnodes) to provide these properly.| |
| 52 | + |
| 53 | +#### `audioNodes` |
| 54 | +These nodes should be connected to the `destination` of the `AudioContext`s provided. |
| 55 | +todo: add an exmple |
| 56 | + |
| 57 | +#### `gainNodes` |
| 58 | +Do not include `GainNode`s within the same tree of `AudioNode`s, only specify the `GainNode` closest to the `AudioContext`'s `destination`. |
| 59 | +todo: add an example |
0 commit comments