Realtime
Realtime in the PHP SDK.
// access
$nexus->realtime()| Symbol | Kind | Summary |
|---|---|---|
Realtime | class | Realtime (rooms) — server-side emit + room management over the /partner/rooms HTTP surface. |
RoomMessage | class | A realtime message: which room, which event(s), and the payload. |
Realtime
classclass Inverge\Nexus\Resource\RealtimeRealtime (rooms) — server-side emit + room management over the /partner/rooms
HTTP surface. Emitting broadcasts to every client currently joined to the room.
__construct
constructorfunction __construct(Inverge\Nexus\NexusClient $client)Parameters
Prop
Type
emit()
methodfunction emit(Inverge\Nexus\RoomMessage|string $room, array|string $events = [], mixed $payload = NULL): arrayEmit one or more named events to a room. Pass a RoomMessage, or a
room name plus events/payload.
Parameters
Prop
Type
Returns array<mixed> — the ack: { ok, room, related, events, recipients }
broadcast()
methodfunction broadcast(iterable $messages): arrayBroadcast to many rooms (each with its own events/payload) in one request.
Each item is a RoomMessage or a loose array (room/name,
event/events, payload).
Parameters
Prop
Type
Returns array<mixed> — { ok, count, results }
emitToRooms()
methodfunction emitToRooms(array $rooms, array|string $events, mixed $payload = NULL): arrayEmit the same event(s) + payload to several rooms in a single request.
$nexus->realtime()->emitToRooms(['orders:1', 'orders:2'], 'location', $payload);Parameters
Prop
Type
Returns array<mixed> — { ok, count, results }
registerRoom()
methodfunction registerRoom(string $name, ?string $type = NULL): arrayRegister (create) a room. Rooms are also auto-created on first join/emit; registering lets you set a type up front.
Parameters
Prop
Type
Returns array<mixed>
rooms()
methodfunction rooms(): arrayList the environment's registered rooms.
Returns array<mixed>
deleteRoom()
methodfunction deleteRoom(string $id): voidParameters
Prop
Type
link()
methodfunction link(string $id, string $relatedId): voidParameters
Prop
Type
unlink()
methodfunction unlink(string $id, string $relatedId): voidParameters
Prop
Type
schema()
methodfunction schema(string $id): arrayParameters
Prop
Type
Returns array<mixed> — */
setSchema()
methodfunction setSchema(string $id, array $schema): arrayParameters
Prop
Type
Returns array<mixed>
enableSchema()
methodfunction enableSchema(string $id, bool $enabled = true): arrayParameters
Prop
Type
Returns array<mixed> — */
clearSchema()
methodfunction clearSchema(string $id): voidParameters
Prop
Type
related()
methodfunction related(string $name): arrayRooms related (linked) to the given room name.
Parameters
Prop
Type
Returns array<mixed>
RoomMessage
classclass Inverge\Nexus\RoomMessageA realtime message: which room, which event(s), and the payload. Use it with
\Inverge\Nexus\Resource\Realtime::emit() and broadcast() instead of
loose arrays.
use Inverge\Nexus\RoomMessage;
$nexus->realtime()->emit(new RoomMessage('orders:42', 'status', ['state' => 'shipped']));
$nexus->realtime()->broadcast([
new RoomMessage('orders:1', 'location', ['lat' => 1]),
new RoomMessage('orders:2', ['location', 'eta'], ['lat' => 2]),
]);__construct
constructorfunction __construct(string $room, array|string $events, mixed $payload = NULL)Parameters
Prop
Type
make()
static methodstatic function make(string $room, array|string $events, mixed $payload = NULL): selfParameters
Prop
Type
Returns self
fromArray()
static methodstatic function fromArray(array $data): selfBuild from a loose array (room/name, event/events, payload) —
used to keep array input working alongside the DTO.
Parameters
Prop
Type
Returns self
toArray()
methodfunction toArray(): arrayReturns array{name: — string, events: list<string>, payload: mixed} */
