Skip to main content
This release is 0 versions behind 24.6.1 — the latest version of @rivet-gg/actor. Jump to latest

🔩 Rivet Actors have built-in RPC, state, and events — the easiest way to build modern applications.

This package works with Deno
This package works with Deno
JSR Score
76%
Published
2 days ago (24.6.1-rc.2)

Rivet Actor

Rivet Actors have built-in RPC, state, and events — the easiest way to build modern applications.

Getting Started

Usage

Make sure you've installed the Rivet CLI.

# Create project
rivet init

# Deploy actor
rivet deploy

See the setup guide for more information.

Example

import { Actor } from "@rivet-gg/actor";
import type { Rpc } from "@rivet-gg/actor";

// Durable state for the counter (https://rivet.gg/docs/state)
interface State {
	count: number;
}

export default class Counter extends Actor<State> {
	// Create the initial state when the actor is first created (https://rivet.gg/docs/state)
	override _onInitialize(): State {
		return { count: 0 };
	}

	// Listen for state changes (https://rivet.gg/docs/lifecycle)
	override _onStateChange(newState: State): void | Promise<void> {
		// Broadcast a state update event to all clients (https://rivet.gg/docs/events)
		this._broadcast("count", newState.count);
	}

	// Expose a remote procedure call for clients to update the count (https://rivet.gg/docs/rpc)
	increment(_rpc: Rpc<Counter>, count: number): number {
		this._state.count += count;
		return this._state.count;
	}
}

Community & Support

License

Apache 2.0

Add Package

deno add jsr:@rivet-gg/actor

Import symbol

import * as actor from "@rivet-gg/actor";

---- OR ----

Import directly with a jsr specifier

import * as actor from "jsr:@rivet-gg/actor";