Metadata provides information about the currently running actor.
Region
Region can be accessed from the context object via c.region
.
c.region
is only supported on Rivet at the moment.
Tags can be accessed from the context object via c.tags
.
For example:
import { actor } from "actor-core";
const chatRoom = actor({
state: {
messages: []
},
actions: {
// Method used to get the channel ID
getChannelId: (c) => {
return c.tags['channel'];
},
addMessage: (c, message) => {
// Use the channel for logging or filtering
const channel = c.tags['channel'] || 'default';
console.log(`Adding message to channel: ${channel}`);
c.state.messages.push({
channel,
message,
timestamp: Date.now()
});
c.broadcast('newMessage', { channel, message });
}
}
});
export default chatRoom;
Actor Name
You can access the actor name with:
const actorName = c.name;
This is useful when you need to know which actor type is running, especially if you have generic utility functions that are shared between different actor implementations.