InvergeDocs
PHPAPI reference

Realtime

Realtime in the PHP SDK.

// access
$nexus->realtime()
SymbolKindSummary
RealtimeclassRealtime (rooms) — server-side emit + room management over the /partner/rooms HTTP surface.
RoomMessageclassA realtime message: which room, which event(s), and the payload.

Realtime

class
class Inverge\Nexus\Resource\Realtime

Realtime (rooms) — server-side emit + room management over the /partner/rooms HTTP surface. Emitting broadcasts to every client currently joined to the room.

View source

__construct

constructor
function __construct(Inverge\Nexus\NexusClient $client)

Parameters

Prop

Type

View source

emit()

method
function emit(Inverge\Nexus\RoomMessage|string $room, array|string $events = [], mixed $payload = NULL): array

Emit 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 }

View source

broadcast()

method
function broadcast(iterable $messages): array

Broadcast 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 }

View source

emitToRooms()

method
function emitToRooms(array $rooms, array|string $events, mixed $payload = NULL): array

Emit 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 }

View source

registerRoom()

method
function registerRoom(string $name, ?string $type = NULL): array

Register (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>

View source

rooms()

method
function rooms(): array

List the environment's registered rooms.

Returns array<mixed>

View source

deleteRoom()

method
function deleteRoom(string $id): void

Parameters

Prop

Type

View source method
function link(string $id, string $relatedId): void

Parameters

Prop

Type

View source method
function unlink(string $id, string $relatedId): void

Parameters

Prop

Type

View source

schema()

method
function schema(string $id): array

Parameters

Prop

Type

Returns array<mixed> — */

View source

setSchema()

method
function setSchema(string $id, array $schema): array

Parameters

Prop

Type

Returns array<mixed>

View source

enableSchema()

method
function enableSchema(string $id, bool $enabled = true): array

Parameters

Prop

Type

Returns array<mixed> — */

View source

clearSchema()

method
function clearSchema(string $id): void

Parameters

Prop

Type

View source method
function related(string $name): array

Rooms related (linked) to the given room name.

Parameters

Prop

Type

Returns array<mixed>

View source

RoomMessage

class
class Inverge\Nexus\RoomMessage

A 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]),
]);
View source

__construct

constructor
function __construct(string $room, array|string $events, mixed $payload = NULL)

Parameters

Prop

Type

View source

make()

static method
static function make(string $room, array|string $events, mixed $payload = NULL): self

Parameters

Prop

Type

Returns self

View source

fromArray()

static method
static function fromArray(array $data): self

Build from a loose array (room/name, event/events, payload) — used to keep array input working alongside the DTO.

Parameters

Prop

Type

Returns self

View source

toArray()

method
function toArray(): array

Returns array{name: — string, events: list<string>, payload: mixed} */

View source

On this page