AUDIO
Source snapshot · 11 November 2026

API reference / ravet_plugin::editor::CLIENT_SCRIPT

Constant CLIENT_SCRIPT 

pub const CLIENT_SCRIPT: &str = "// RAVET editor client, injected into every plug-in editor page.\n// It implements the editor protocol (protocol 1) and exposes window.ravetPlugin.\n(() => {\n  \"use strict\";\n  const listeners = { info: [], values: [], product: [] };\n  let info = null;\n  let sequence = -1;\n  const values = {};\n  const send = (message) => {\n    const handler = window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.ravet;\n    if (handler) handler.postMessage(message);\n  };\n  const emit = (type, payload) => {\n    for (const listener of listeners[type]) {\n      try { listener(payload); } catch (error) { console.error(error); }\n    }\n  };\n  // Called by the plug-in with each message from the plug-in to the editor.\n  window.ravetUpdate = (message) => {\n    if (!message || typeof message !== \"object\") return;\n    switch (message.type) {\n      case \"info\":\n        info = message;\n        emit(\"info\", info);\n        break;\n      case \"snapshot\":\n      case \"changes\":\n        if (typeof message.sequence !== \"number\" || message.sequence <= sequence) return;\n        sequence = message.sequence;\n        Object.assign(values, message.parameters);\n        emit(\"values\", { values: { ...values }, changed: message.parameters,\n          telemetry: message.telemetry, product: message.product });\n        break;\n      case \"product\":\n        emit(\"product\", message.data);\n        break;\n    }\n  };\n  const parameter = (key) => info && info.parameters.find((p) => p.key === key);\n  window.ravetPlugin = {\n    /** Product and parameter metadata, or null before the first `info`. */\n    get info() { return info; },\n    /** Current physical value of a parameter. */\n    value(key) { return values[key]; },\n    /** Current value of a parameter mapped to 0..1. */\n    normalized(key) {\n      const p = parameter(key);\n      const v = values[key];\n      if (!p || typeof v !== \"number\") return undefined;\n      if (p.scale === \"logarithmic\") return Math.log(v / p.minimum) / Math.log(p.maximum / p.minimum);\n      return (v - p.minimum) / (p.maximum - p.minimum);\n    },\n    /** Listen for \"info\", \"values\" or \"product\". */\n    on(type, listener) {\n      if (!listeners[type]) throw new Error(`unknown event ${type}`);\n      listeners[type].push(listener);\n      if (type === \"info\" && info) listener(info);\n    },\n    /** One complete edit, such as a click or typed value. */\n    set(key, value) { send({ type: \"commit\", key, value }); },\n    setNormalized(key, normalized) { send({ type: \"commit\", key, normalized }); },\n    /** A continuous gesture: begin, any number of updates, end. */\n    begin(key) { send({ type: \"begin\", key }); },\n    update(key, value) { send({ type: \"set\", key, value }); },\n    updateNormalized(key, normalized) { send({ type: \"set\", key, normalized }); },\n    end(key) { send({ type: \"end\", key }); },\n    /** A product-defined message to the plug-in. */\n    send(data) { send({ type: \"product\", data }); },\n  };\n  const ready = () => send({ type: \"ready\", protocol: 1 });\n  if (document.readyState === \"loading\") document.addEventListener(\"DOMContentLoaded\", ready, { once: true });\n  else ready();\n})();\n";
Expand description

The editor client script injected into every editor page.