Skip to content
docsv0.1.0

MercureService

Publishes updates to a Mercure hub and mints the self-signed JWTs the hub expects for both server-side publish and browser-side subscribe. The hub is not called via any HTTP client abstraction — publish() drives cURL directly, so no other Milpa package is required to use this class.

MercureService::__construct()

public function __construct(string $hubUrl, string $publicUrl, string $publisherKey, string $subscriberKey):

Parameters

Parameters of __construct()
NameTypeDescription
$hubUrlstringInternal hub URL used for server-side POST /.well-known/mercure
$publicUrlstringPublic hub URL the browser connects to for EventSource/SSE
$publisherKeystringHMAC secret used to sign publisher JWTs
$subscriberKeystringHMAC secret used to sign subscriber JWTs

MercureService::publish()

public function publish(string $topic, array $data): void

Publish data to a Mercure topic.

Parameters

Parameters of publish()
NameTypeDescription
$topicstringTopic URI (e.g. "conversations/123/messages")
$dataarray<string, mixed>Payload to send as JSON

MercureService::generateSubscriberJwt()

public function generateSubscriberJwt(array $topics): string

Generate a subscriber JWT for the browser EventSource connection.

Parameters

Parameters of generateSubscriberJwt()
NameTypeDescription
$topicsstring[]Topics the subscriber can listen to

MercureService::getPublicUrl()

public function getPublicUrl(): string

The public hub URL browsers should open their EventSource connection against.