From 926d15e02c3a29900c1a4e4219382f0395664682 Mon Sep 17 00:00:00 2001 From: Geraint Luff Date: Thu, 24 Oct 2024 22:48:37 +0100 Subject: [PATCH] Start `clap.web` draft --- include/clap/all.h | 1 + include/clap/ext/draft/web.h | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 include/clap/ext/draft/web.h diff --git a/include/clap/all.h b/include/clap/all.h index 54bbfbc4..b7ba57ac 100644 --- a/include/clap/all.h +++ b/include/clap/all.h @@ -13,3 +13,4 @@ #include "ext/draft/tuning.h" #include "ext/draft/undo.h" #include "ext/draft/scratch-memory.h" +#include "ext/draft/web.h" diff --git a/include/clap/ext/draft/web.h b/include/clap/ext/draft/web.h new file mode 100644 index 00000000..2d294ae6 --- /dev/null +++ b/include/clap/ext/draft/web.h @@ -0,0 +1,52 @@ +#pragma once + +static CLAP_CONSTEXPR const char CLAP_EXT_WEB[] = "clap.web/1"; + +#ifdef __cplusplus +extern "C" { +#endif + +/// @page Web +/// +/// This extension enables the plugin to provide the start-page for a webview UI, and exchange +/// messages back and forth. +/// +/// Messages are received in the webview using a standard MessageEvent, with the data in an +/// ArrayBuffer. They are posted back to the plugin using window.parent.postMessage(), with the +/// data in an ArrayBuffer or TypedArray. + +typedef struct clap_plugin_web { + // Returns the URL for the webview's initial navigation, as a null-terminated UTF-8 string. + // If this URL is relative, it is resolved relative to the plugin (bundle) directory, and + // cannot be outside it. The host may use any protocol to serve this content, and the page + // must not assume that the root of the domain is the root of the bundle. The URL may also be + // absolute, including a `file://` URL. + // Returns true on success. + // [main-thread] + bool(CLAP_ABI *get_start)(const clap_plugin_t *plugin, + char *out_buffer, + uint32_t out_buffer_capacity); + + // Receives a single message from the webview. + // Returns true on success. + // [main-thread] + bool(CLAP_ABI *receive)(const clap_plugin_t *plugin, const void *buffer, uint32_t size); + +} clap_plugin_web_t; + +typedef struct clap_host_web { + // Checks whether the webview is open (and ready to receive messages) + // [thread-safe] + bool(CLAP_ABI *is_open)(const clap_host_t *host); + + // Sends a single message to the webview. + // It must not allocate or block if called from the audio thread. + // Returns true on success. + // [thread-safe] + bool(CLAP_ABI *send)(const clap_host_t *host, const void *buffer, uint32_t size); + +} clap_host_web_t; + +#ifdef __cplusplus +} +#endif