nexis_wasm_plugin 0.1.4

Rust helper crate for authoring Nexis runtime-loaded WASM room plugins.
Documentation
  • Coverage
  • 0%
    0 out of 16 items documented0 out of 11 items with examples
  • Size
  • Source code size: 12.81 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 504.95 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • TriForMine/nexis
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • TriForMine

nexis_wasm_plugin

Rust helper crate for building Nexis runtime-loaded WASM room plugins.

This crate gives plugin authors:

  • a RoomPlugin trait with lifecycle hooks
  • a PluginOutput type for returning state and optional events
  • an export_plugin! macro that exports the host ABI functions

Install

[dependencies]

nexis_wasm_plugin = "0.1.5"

serde_json = "1"

Minimal Plugin

use nexis_wasm_plugin::{export_plugin, PluginOutput, RoomPlugin};
use serde_json::{json, Value};

#[derive(Default)]
struct CounterPlugin;

impl RoomPlugin for CounterPlugin {
    fn initial_state(&self) -> Value {
        json!({ "counter": 0 })
    }

    fn on_message(&self, state: &Value, input: &Value) -> PluginOutput {
        if input.get("type").and_then(Value::as_str) == Some("inc") {
            let by = input
                .get("data")
                .and_then(|data| data.get("by"))
                .and_then(Value::as_i64)
                .unwrap_or(1);
            let current = state.get("counter").and_then(Value::as_i64).unwrap_or(0);
            let next = current + by;
            return PluginOutput::state_with_event(
                json!({ "counter": next }),
                json!({ "type": "counter.updated", "data": { "counter": next } }),
            );
        }

        PluginOutput::state(state.clone())
    }
}

export_plugin!(CounterPlugin);

Build for Nexis Runtime

rustup target add wasm32-unknown-unknown

cargo build --target wasm32-unknown-unknown --release

Use the generated .wasm in NEXIS_WASM_ROOM_PLUGINS.

Compatibility

nexis_wasm_plugin follows Nexis 0.x compatibility policy: APIs can evolve between minor releases. Pin and test before upgrading.