Nexify Chat Demo
Interactive real-time chat client and developer playground demonstrating bidirectional full-duplex communication via Nexify. Nexify operates on the exact same URL and port as your Lacelium application.
Experience the full-page dark studio featuring multi-channel chat, live DOM fragment swaps, raw wire frame telemetry inspection, and HTTP REST bridge.
1. Nexify Real-Time Architecture
Nexify is Lacelium's native asynchronous messaging engine. By matching the web application's host and port directly, it eliminates secondary port bindings, CORS mismatches, and complex firewall setups while sustaining thousands of concurrent client connections.
Same URL:Port Design
Nexify clients connect directly to ws://localhost:7000 (or your active application port) or wss://yourdomain.com without switching to a different port. Reverse proxies and local development servers upgrade standard HTTP requests to full-duplex Nexify real-time streaming seamlessly.
2. Starting the Nexify Server
Run the background Nexify engine directly from the CLI:
# Start HTTP server together with Nexify
php console serve
# Or launch standalone Nexify daemon:
php console nexify:serve
# Stop background services:
php console nexify:stop
Environment configuration in your .env file:
# Nexify Configuration (matches APP_URL by default)
NEXIFY_HOST=localhost
NEXIFY_PORT=7000
NEXIFY_PUBLIC_URL=
NEXIFY_AUTO_START=true
NEXIFY_ALLOWED_ORIGINS=*
3. Protocol & JSON Message Schemas
All communication frames are encoded in standard serialized JSON with a mandatory type field.
| Type | Payload Fields | Description |
|---|---|---|
join |
room, user, [token] |
Subscribes the connection to a specific channel room and broadcasts presence. |
chat |
room, user, message, [timestamp] |
Broadcasts a text message to all active participants in the channel. |
presence |
room, user, event: "join"|"leave" |
Emitted by the server when peers enter or exit a channel. |
fragment |
selector, html, [action] |
Triggers real-time HTML fragment replacement on target DOM selectors. |
ping / pong |
ts |
Keep-alive heartbeat frames preventing proxy timeout disconnects. |
4. Server-Side Broadcasting from PHP Controllers
Publish events to connected clients directly from your standard PHP controllers using the global nexify() helper:
namespace App\Http\Controllers;
use Lacelium\Core\Http\Request;
use Lacelium\Core\Http\Response;
class OrderController
{
public function complete(Request $request, Response $response): Response
{
$orderId = $request->input('order_id');
// Broadcast chat notification via Nexify
nexify()->broadcastChat('general', 'NexifyBot', "Order #{$orderId} was processed successfully!");
// Live DOM fragment swap
nexify()->broadcastFragment('#order-status', '<span class="badge bg-success">Fulfilled</span>');
return $response->json(['success' => true]);
}
}
5. Client-Side JavaScript Integration (Nexify)
Client integration resolves the host and port dynamically from the active page:
class NexifyClient {
constructor(options = {}) {
// Automatically match Lacelium's same URL and port
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
this.url = options.url || `${protocol}//${window.location.host}`;
this.room = options.room || 'general';
this.user = options.user || 'guest';
this.socket = null;
}
connect() {
this.socket = new WebSocket(this.url);
this.socket.addEventListener('open', () => {
// Join room on connection
this.send({ type: 'join', room: this.room, user: this.user });
});
this.socket.addEventListener('message', (event) => {
const data = JSON.parse(event.data);
if (data.type === 'fragment' && data.selector && data.html) {
const el = document.querySelector(data.selector);
if (el) el.innerHTML = data.html;
}
});
}
send(data) {
if (this.socket && this.socket.readyState === WebSocket.OPEN) {
this.socket.send(JSON.stringify(data));
}
}
}
Next Steps
- Launch the full-page developer studio in Nexify Wire Studio.
- Review the protocol architecture and JSON wire frame schemas in Nexify Real-Time API.
- Inspect live components and verify WebSocket status in Live Sandbox.