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

feat: add routing of messages between the property inspector and the plugin #33

Merged
merged 33 commits into from
Apr 10, 2024

Conversation

GeekyEggo
Copy link
Member

@GeekyEggo GeekyEggo commented Mar 27, 2024

Adds routing of messages between the plugin and its property inspector.

Example

Plugin

import streamDeck from "@elgato/streamdeck";
streamDeck.ui.registerRoute("/get-names", (req, res) => {
    // access to the request and a responder -alternatively, a response can be returned.
    return ["Mario", "Peach", "Luigi"];
});

Property Inspector Side

const res = await streamDeck.plugin.fetch("/get-names");
// res.body = ["Mario", "Luigi", "Peach"]

Changes

Plugin

  • Add PropertyInspector class.
    • Add fetch to fetch requests from the property inspector.
  • Add streamDeck.ui.current to track the current property inspector.
  • Add streamDeck.ui.registerRoute to register the routing of requests from the property inspector.
  • Add @route decorator to provide routing of an action's function.
  • Mark sendToPlugin and sendToPropertyInspector as deprecated.

Property Inspector

  • Add streamDeck.plugin fetch to send fetch requests to the plugin.
  • Add streamDeck.plugin.registerRoute to register the routing of requests from the plugin.
  • Mark sendToPlugin and sendToPropertyInspector as deprecated.

Internal

  • Add MessageGateway class for handling bi-directional requests / responses.
  • Update UI namespace to be a controller class.
  • Fix trace logging of the connection.

…aries

Sadly, when utilizing rollup-plugin-dts to bundle declarations into a single file, summaries for "export import *" were being lost. This result in quiet issues when creating the .d.ts file, so has [temporarily] been removed.
LICENSE Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 2024 required here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot, re-added.

* @param options Optional routing configuration.
* @returns This instance with the route registered.
*/
public route<TBody extends JsonValue = JsonValue>(path: string, handler: UnscopedMessageHandler<TAction, TBody>, options?: RouteConfiguration<TAction>): this {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there ever any circumstance where we might want to allow a route to be unregistered?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is, but not at the moment. When transient actions are available, and they're added / removed from memory as needed, we'll need to ensure the routes for those context/action combinations are also removed appropriately. This also drove the decision to not return this on the publicly exposed registerRoute as that will likely return a Disposable to allow for the route to be removed.

public registerRoute<TBody extends JsonValue = JsonValue, TSettings extends JsonObject = JsonObject>(
path: string,
handler: MessageHandler<TBody, TSettings>,
options?: RouteConfiguration<Action>
): void {
router.route(path, handler, options);
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

registerRoute now returns an IDisposable 🥳

ChekTek
ChekTek previously approved these changes Mar 27, 2024
@GeekyEggo GeekyEggo merged commit 08f1d7b into main Apr 10, 2024
4 checks passed
@GeekyEggo GeekyEggo deleted the routing branch April 10, 2024 11:56
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.

3 participants