WebSocketController

Source: backend/app/Core/Http/Controllers/WebSocketController.php. Contracts below describe mounted actions, not every internal helper. Examples are illustrative and were not sent. Request examples assume an appropriate local environment and authenticated session where required.

Global IP bans and uninstalled middleware can short-circuit the controller. Uninstalled API requests return503 {error:System is not installed,installed:false}. Authenticated routes require a Sanctum session/token and pass the banned-user gate; they can fail401/403 before action execution. JSON validation normally returns422 {message,errors} unless overridden below. Generic framework failures can return500; do not infer transaction rollback from a failure response.

authorizeChannel {#authorize-channel}

  • POST api/v1/ws/auth — middleware: api, Illuminate\Auth\Middleware\Authenticate:sanctum, App\Core\Middleware\CheckUserBanned.

Input/defaults. channel_name from body, no validation/default; must be a string for service signature. Authenticated user required. socket_id is not used by this action.

Behaviour and effects. Calls WebSocketService.authorizeChannel. user.<id> allows matching integer user ID; exact admin requires admin role; all other channel strings return true in current service (including unrecognized private/presence-style names). Authorized presence- prefix returns user_id and user_info{id,username,avatar}; otherwise auth:true. This is not a Pusher signature response, and does not join presence or store messages.

Response. Successful handler status200, JSON unless noted. Representative shape (placeholder strings indicate service/model data):

{"auth":true}

Errors and status. 403 {message:Unauthorized} when service denies;401 auth/403 banned gate. Missing/nonstring channel may500 rather than 422. Do not infer arbitrary private channel protection from the action name.

Example request.

POST /api/v1/ws/auth HTTP/1.1
Host: localhost
Accept: application/json
Authorization: Bearer <local-test-token>
Content-Type: application/json

{"channel_name": "user.1"}

poll {#poll}

  • POST api/v1/ws/poll — middleware: api, Illuminate\Auth\Middleware\Authenticate:sanctum, App\Core\Middleware\CheckUserBanned.

Input/defaults. channels required array; channels.* string; since nullable string. No date validation; channel array has no explicit max size.

Behaviour and effects. Skips unauthorized channels rather than returning 403, reads cached ws_messages:<channel>, filters timestamps lexically greater than since, merges and sorts timestamp ascending. No blocking wait: this is an immediate polling response, despite long-polling comment. Cache stores last100 per channel for 1hour; no server pagination/cursor beyond timestamp. Duplicate channels can duplicate messages. No message removal/read acknowledgement.

Response. Successful handler status200, JSON unless noted. Representative shape (placeholder strings indicate service/model data):

{"messages":[],"timestamp":"2026-10-23T12:00:00+00:00"}

Errors and status. 422 validation;401/403 middleware; cache/service failures500. Unsupported channel names are allowed by current generic service fallback.

Example request.

POST /api/v1/ws/poll HTTP/1.1
Host: localhost
Accept: application/json
Authorization: Bearer <local-test-token>
Content-Type: application/json

{"channels": ["global"], "since": "2026-10-23T11:59:00+00:00"}

onlineCount {#online-count}

  • GET api/v1/ws/online-count — middleware: api, Illuminate\Auth\Middleware\Authenticate:sanctum, App\Core\Middleware\CheckUserBanned.

Input/defaults. No input.

Behaviour and effects. Reads online_users_count cached value, default 0. Not an authoritative count of per-user online keys; the current updateOnlineUsers helper reads/broadcasts existing count without recalculating it.

Response. Successful handler status200, JSON unless noted. Representative shape (placeholder strings indicate service/model data):

{"count":0}

Errors and status. 401/403 middleware; cache failure500.

Example request.

GET /api/v1/ws/online-count HTTP/1.1
Host: localhost
Accept: application/json
Authorization: Bearer <local-test-token>

heartbeat {#heartbeat}

  • POST api/v1/ws/heartbeat — middleware: api, Illuminate\Auth\Middleware\Authenticate:sanctum, App\Core\Middleware\CheckUserBanned.

Input/defaults. No body fields used. Authenticated user supplies identity.

Behaviour and effects. Writes user_online:<id> cache key with 5minute TTL then broadcasts global online_count using existing cached count and stores polling message. Count is not recomputed by the helper. Cache/broadcast effects can partially survive errors; later expiry or setOffline clears online flag.

Response. Successful handler status200, JSON unless noted. Representative shape (placeholder strings indicate service/model data):

{"status":"ok","online_count":0}

Errors and status. 401/403 middleware; cache/broadcast failure500. A200 does not validate a live socket connection.

Example request.

POST /api/v1/ws/heartbeat HTTP/1.1
Host: localhost
Accept: application/json
Authorization: Bearer <local-test-token>
Content-Type: application/json

{}

presenceMembers {#presence-members}

  • GET api/v1/ws/presence/{channel} — middleware: api, Illuminate\Auth\Middleware\Authenticate:sanctum, App\Core\Middleware\CheckUserBanned.

Input/defaults. Required channel path string, passed to service authorization. No join operation or input body.

Behaviour and effects. Checks same authorization rules, reads presence:<channel> cache and array_values returns members list. Member shape when written by service is id,username,avatar,joined_at. Controller does not join/leave presence.

Response. Successful handler status200, JSON unless noted. Representative shape (placeholder strings indicate service/model data):

{"members":[]}

Errors and status. 403 {message:Unauthorized} for denied channel;401 auth and403 banned middleware; cache/runtime failures500.

Example request.

GET /api/v1/ws/presence/{channel} HTTP/1.1
Host: localhost
Accept: application/json
Authorization: Bearer <local-test-token>

Internal implementation boundary

Constructors inject services. Internal helper methods and unmounted methods are source-reference material, not additional HTTP endpoints. Source inspection was performed; request execution, browser behaviour and production availability remain unverified.