#P1659
POST /v2/core/socket/send
Core Socket: Send Message
این اندپوینت یک پیام را از طریق سیستم Broadcasting لاراول ارسال میکند. پیام به Event TradeOperation پاس داده میشود و با toOthers() فقط به کلاینتهای دیگر (غیر از فرستنده) Broadcast میشود.
Request Overview
URL:
/v2/core/socket/sendMethod: POST
Controller: CoreController@socketSendMessage
Middleware Stack: authWithJwt → core
Access Control
- JWT معتبر لازم است
- میانافزار core تنها وقتی اجازه میدهد که:
operator.branch == "[0]"
Request Body Schema
| Field | Type | Required | Description |
|---|---|---|---|
| message | string | yes | متن پیام که باید از طریق WebSocket (Broadcast) ارسال شود |
Broadcast Logic
پس از دریافت message:
- یک Event از نوع
TradeOperationساخته میشود:
broadcast(new TradeOperation($message))
- فقط به دیگر کلاینتها ارسال میشود (نه فرستنده):
->toOthers()
- Broadcasting باید در کانالهای Laravel Echo/Pusher/SocketServer پیکربندی شده باشد
Response (Success)
{
"status": "Message Sent!"
}
Response (Error)
در این نسخه از کد هندلکردن Exception وجود ندارد، اما در صورت بروز خطا در سطح سیستم (مثلاً عدم کارکرد Broadcast Driver)، لاراول پاسخ خطا برمیگرداند.
Flowchart
Validate JWT & Core Middleware
↓
Extract message from request
↓
broadcast(new TradeOperation(message))
↓
Send to Others (WebSocket Clients)
↓
Return JSON: "Message Sent!"