SocketContext class

Represents the context of a WebSocket event/message.

This class encapsulates the client, the message, and any shared state for the duration of the event processing. It replaces the HTTP-bound Request object for WebSocket interactions.

Constructors

SocketContext({required SocketClient client, required SocketPacket packet})

Properties

client SocketClient
The client that sent the message.
final
data → dynamic
Get the message payload data.
no setter
event String
Get the event name.
no setter
hashCode int
The hash code for this object.
no setterinherited
id String?
Get the message ID (if any).
no setter
namespace String?
Get the event namespace (e.g., "chat" from "chat:message").
no setter
packet SocketPacket
The parsed socket packet.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

broadcast(String event, dynamic data) → void
Broadcast to all subscribers of the event.
broadcastTo(String room, String event, dynamic data) → void
Broadcast to a room (excluding sender).
emit(String event, dynamic data) → void
Helper to send a reply to the client.
error(String message, {int code = 400, dynamic details}) → void
Helper to send an error reply.
get<T>(String key) → T?
Get a context attribute.
has(String key) bool
Check if an attribute exists.
join(String room) → void
Join a room.
leave(String room) → void
Leave a room.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
payload<T>() → T
Get the payload as a specific type.
run<R>(R body()) → R
Run code in a zone with this context.
set(String key, dynamic value) → void
Set a context attribute.
to(String room, String event, dynamic data) → void
Broadcast to a room (including sender).
toString() String
A string representation of this object.
inherited
validate(Map<String, dynamic> rules, {Map<String, String> messages = const {}}) Future<void>
Validate the payload against rules.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

current SocketContext
Get the current socket context from the zone.
no setter