{"id":480129,"date":"2026-05-18T12:43:01","date_gmt":"2026-05-18T12:43:01","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=480129"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=480129","title":{"rendered":"Centrifugo\u00a0JS\u00a0client\u00a0\u0432\u00a0Laravel:\u00a0frontend\u00a0\u0438\u00a0production"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>Real-time \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0435 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0442\u043e\u043c, \u0447\u0442\u043e backend \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432 Centrifugo. \u042d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u044b. \u0412\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0435 \u0438 \u0432 \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u0438: \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u043f\u043e\u0442\u0435\u0440\u044f \u0441\u0435\u0442\u0438, \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f, Nginx, \u0441\u0435\u043a\u0440\u0435\u0442\u044b, \u043b\u043e\u0433\u0438 \u0438 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433.<\/p>\n<p>\u041d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0440\u0430\u0441\u0438\u0432\u043e: \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b\u043e\u0441\u044c, WebSocket \u043f\u043e\u043b\u0443\u0447\u0438\u043b payload, \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043e\u0431\u043d\u043e\u0432\u0438\u043b\u0441\u044f. \u041f\u043e\u0442\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432 production, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043d\u043e\u0443\u0442\u0431\u0443\u043a \u043f\u043e\u0441\u043b\u0435 \u0441\u043d\u0430, \u0441\u0435\u0442\u044c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0441 Wi-Fi \u043d\u0430 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u0443\u044e, \u0442\u043e\u043a\u0435\u043d \u0438\u0441\u0442\u0435\u043a\u0430\u0435\u0442, Nginx \u0440\u0435\u0436\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435, Centrifugo \u043f\u0438\u0448\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, frontend \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442. \u0418 \u0432\u043e\u0442 \u0443\u0436\u0435 real-time \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u201c\u0438\u043d\u043e\u0433\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0441\u0430\u043c \u043e\u0436\u0438\u0432\u0430\u0435\u0442, \u0438\u043d\u043e\u0433\u0434\u0430 \u043d\u0435\u0442\u201d.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u0437\u0430 \u0447\u0442\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434 \u0432 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 Laravel + Centrifugo, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 Centrifuge JS client \u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u044f WebSocket-\u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0435 \u0432\u0442\u043e\u0440\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c, \u0430 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u0443\u0441\u043f\u0435\u0445\u0430.<\/p>\n<p>\u0412 production real-time \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0432\u0430\u0436\u043d\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u043d\u043e \u0438:<\/p>\n<ul>\n<li>\n<p>\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c frontend \u0447\u0435\u0440\u0435\u0437 Centrifuge JS client;<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u044b\u0432\u0430 \u0441\u0435\u0442\u0438;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c connection token \u0438 subscription token;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0435 \u0441\u0447\u0438\u0442\u0430\u0442\u044c WebSocket \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u0438\u0441\u0442\u0438\u043d\u044b;<\/p>\n<\/li>\n<li>\n<p>\u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c Nginx;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0435 \u0441\u0432\u0435\u0442\u0438\u0442\u044c \u0441\u0435\u043a\u0440\u0435\u0442\u044b \u0438 API key \u043d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0435;<\/p>\n<\/li>\n<li>\n<p>\u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p>\u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442\u044c Centrifugo \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<\/li>\n<\/ul>\n<p>\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u043c\u044b\u0441\u043b\u044c:<\/p>\n<p>WebSocket \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u043d\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0443\u043c\u0435\u0442\u044c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0447\u0435\u0440\u0435\u0437 HTTP.<\/p>\n<h3>\u0413\u0434\u0435 frontend \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 Laravel + Centrifugo<\/h3>\n<p>\u0412 \u0442\u0438\u043f\u043e\u0432\u043e\u0439 \u0441\u0445\u0435\u043c\u0435 \u0440\u043e\u043b\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u0430\u043a:<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/bf0\/3c8\/b90\/bf03c8b90874234b5071468f2e501bb6.png\" alt=\"\u0421\u0445\u0435\u043c\u0430 real-time \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b Laravel, Centrifugo \u0438 Frontend: Laravel \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0442\u043e\u043a\u0435\u043d\u044b \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, Centrifugo \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 WebSocket-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u043a\u0430\u043d\u0430\u043b\u0430\u043c\u0438, Frontend \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 HTTP.\" title=\"\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 Laravel + Centrifugo + Frontend \u0434\u043b\u044f real-time \u0441\u0438\u0441\u0442\u0435\u043c\u044b\" width=\"1024\" height=\"438\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/bf0\/3c8\/b90\/bf03c8b90874234b5071468f2e501bb6.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/bf0\/3c8\/b90\/bf03c8b90874234b5071468f2e501bb6.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 Laravel + Centrifugo + Frontend \u0434\u043b\u044f real-time \u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/figcaption><\/div>\n<\/figure>\n<p>Frontend \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0430\u043c \u0440\u0435\u0448\u0430\u0442\u044c \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0443. \u041e\u043d \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043f\u0440\u0430\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0447\u0443\u0436\u0438\u043c \u043a\u0430\u043d\u0430\u043b\u0430\u043c. \u041e\u043d \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u043d\u0430\u0442\u044c \u0441\u0435\u043a\u0440\u0435\u0442 Centrifugo. \u0415\u0433\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u043e\u0449\u0435 \u0438 \u0441\u0442\u0440\u043e\u0436\u0435: \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f, \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f, \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c UI \u0438 \u043f\u0440\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0445 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435.<\/p>\n<h3>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 Centrifuge JS client<\/h3>\n<p>\u041d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0435 \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 JavaScript-\u043a\u043b\u0438\u0435\u043d\u0442 Centrifugo \u2014\u00a0<code>centrifuge<\/code>.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f:<\/p>\n<pre><code>import { Centrifuge } from 'centrifuge';const centrifuge = new Centrifuge('wss:\/\/example.com\/connection\/websocket', {    token: connectionToken,});centrifuge.connect();<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:87px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p><code>connectionToken<\/code>\u00a0frontend \u043d\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u0430\u043c. \u041e\u043d \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u0435\u0433\u043e \u0443 Laravel:<\/p>\n<pre><code>async function fetchConnectionToken() {    const response = await fetch('\/api\/realtime\/connection-token', {        credentials: 'include',        headers: {            Accept: 'application\/json',        },    });    if (!response.ok) {        throw new Error('Failed to fetch Centrifugo connection token.');    }    const data = await response.json();    return data.token;}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0430\u0436\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442: frontend \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 token \u043e\u0442 backend, \u0430 \u043d\u0435 \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u0435\u043a\u0440\u0435\u0442\u044b Centrifugo.<\/p>\n<p>\u0421\u0435\u043a\u0440\u0435\u0442\u044b \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435. \u041d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442 \u0443\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u0439 JWT, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<\/p>\n<h3>\u041f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 \u043d\u0430 \u043a\u0430\u043d\u0430\u043b<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u0430\u043d\u0430\u043b.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u0430\u043d\u0430\u043b:<\/p>\n<pre><code>const subscription = centrifuge.newSubscription(`user:${userId}`);subscription.on('publication', function (context) {    handleRealtimePublication(context.data);});subscription.on('subscribed', function () {    console.log('Subscribed to user channel.');});subscription.on('error', function (context) {    console.error('Subscription error.', context);});subscription.subscribe();<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043a\u0430\u043d\u0430\u043b \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0439, subscription token \u0442\u043e\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f backend-\u043e\u043c.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code>const subscription = centrifuge.newSubscription(`private:user:${userId}`, {    token: subscriptionToken,});<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0418 \u0441\u043d\u043e\u0432\u0430:\u00a0<code>subscriptionToken<\/code>\u00a0\u0432\u044b\u0434\u0430\u0451\u0442 Laravel. \u0424\u0440\u043e\u043d\u0442\u0435\u043d\u0434 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u0430\u043c \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0447\u0443\u0436\u043e\u0439 \u043a\u0430\u043d\u0430\u043b.<\/p>\n<h3>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0439<\/h3>\n<p>\u0421\u0430\u043c\u0430\u044f \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u2014 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u043e frontend \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 payload.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e\u0439 payload:<\/p>\n<pre><code>{    \"id\": 123,    \"user\": {        \"id\": 10,        \"name\": \"Max\",        \"email\": \"max@example.com\",        \"roles\": [\"admin\"],        \"settings\": {}    },    \"order\": {        \"id\": 456,        \"items\": [],        \"payments\": [],        \"history\": []    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 payload \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 WebSocket \u0432 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 REST API. \u041f\u043e\u0442\u043e\u043c \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c\u044e, \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u0432\u0435\u0440\u0441\u0438\u044f\u043c\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0430.<\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u0438\u0439 payload \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439:<\/p>\n<pre><code>{    \"type\": \"order.status_changed\",    \"id\": 456,    \"status\": \"paid\"}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0438\u043b\u0438:<\/p>\n<pre><code>{    \"type\": \"notification.created\",    \"id\": 987}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>Frontend \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438 \u0440\u0435\u0448\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c:<\/p>\n<pre><code>function handleRealtimePublication(payload) {    switch (payload.type) {        case 'order.status_changed':            updateOrderStatus(payload.id, payload.status);            return;        case 'notification.created':            incrementNotificationsCounter();            return;        default:            console.warn('Unknown realtime event type.', payload);    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p><code>switch<\/code>\u00a0\u0437\u0434\u0435\u0441\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u0435\u043d. \u042d\u0442\u043e \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0435, \u0430 \u043d\u0435 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430 \u043d\u0430 300 \u0441\u0442\u0440\u043e\u043a. \u0415\u0441\u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0441\u0442\u0430\u043d\u0435\u0442 \u043c\u043d\u043e\u0433\u043e, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 map \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432.<\/p>\n<pre><code>const handlers = {    'order.status_changed': handleOrderStatusChanged,    'notification.created': handleNotificationCreated,};function handleRealtimePublication(payload) {    const handler = handlers[payload.type];    if (handler === undefined) {        console.warn('Unknown realtime event type.', payload);        return;    }    handler(payload);}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0422\u0430\u043a \u043a\u043e\u0434 \u043f\u0440\u043e\u0449\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c.<\/p>\n<h3>WebSocket \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u0438\u0441\u0442\u0438\u043d\u044b<\/h3>\n<p>\u042d\u0442\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442.<\/p>\n<p>WebSocket-\u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u043f\u0440\u0438\u0439\u0442\u0438:<\/p>\n<ul>\n<li>\n<p>\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0442\u0435\u0440\u044f\u043b \u0441\u0435\u0442\u044c;<\/p>\n<\/li>\n<li>\n<p>\u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0443\u0448\u0451\u043b \u0432 sleep;<\/p>\n<\/li>\n<li>\n<p>\u043d\u043e\u0443\u0442\u0431\u0443\u043a \u043f\u0440\u043e\u0441\u043d\u0443\u043b\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0447\u0430\u0441;<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u043e\u0440\u0432\u0430\u043b\u043e\u0441\u044c;<\/p>\n<\/li>\n<li>\n<p>\u0442\u043e\u043a\u0435\u043d \u0438\u0441\u0442\u0451\u043a;<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 \u043d\u0435 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0430\u0441\u044c;<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0448\u043b\u043e \u0440\u0430\u043d\u044c\u0448\u0435, \u0447\u0435\u043c frontend \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043b \u043d\u0443\u0436\u043d\u044b\u0439 state.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 real-time \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043b\u0443\u0447\u0448\u0435 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043a\u0430\u043a \u0441\u0438\u0433\u043d\u0430\u043b:<\/p>\n<ul>\n<li>\n<p>\u0447\u0442\u043e-\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u043d\u043e\u0432\u0438 \u0447\u0430\u0441\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 HTTP.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code>async function handleOrderStatusChanged(payload) {    if (currentOrderId !== payload.id) {        return;    }    await reloadOrder(payload.id);}async function reloadOrder(orderId) {    const response = await fetch(`\/api\/orders\/${orderId}`, {        credentials: 'include',        headers: {            Accept: 'application\/json',        },    });    if (!response.ok) {        throw new Error('Failed to reload order.');    }    const order = await response.json();    renderOrder(order);}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c UI \u043f\u0440\u044f\u043c\u043e \u0438\u0437 payload. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0447\u0451\u0442\u0447\u0438\u043a \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439. \u041d\u043e \u0434\u043b\u044f \u0432\u0430\u0436\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043b\u0443\u0447\u0448\u0435 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 HTTP.<\/p>\n<h3>\u041f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u0442\u0435\u0440\u044f \u0441\u0435\u0442\u0438<\/h3>\n<p>Centrifuge JS client \u0443\u043c\u0435\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f, \u043d\u043e frontend \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u043b\u0443\u0448\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f:<\/p>\n<pre><code>centrifuge.on('connecting', function (context) {    console.log('Connecting to Centrifugo.', context);    showRealtimeStatus('connecting');});centrifuge.on('connected', function (context) {    console.log('Connected to Centrifugo.', context);    showRealtimeStatus('connected');});centrifuge.on('disconnected', function (context) {    console.warn('Disconnected from Centrifugo.', context);    showRealtimeStatus('disconnected');});<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0439 \u043a\u0440\u0430\u0441\u043d\u044b\u0439 \u0431\u0430\u043d\u043d\u0435\u0440. \u041d\u043e \u0434\u043b\u044f \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u0441\u0442\u0430\u0442\u0443\u0441 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0432\u0430\u0436\u0435\u043d.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<ul>\n<li>\n<p>\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u0430\u0431\u0438\u043d\u0435\u0442 \u0441 \u043f\u043b\u0430\u0442\u0435\u0436\u0430\u043c\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0430\u0434\u043c\u0438\u043d\u043a\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438;<\/p>\n<\/li>\n<li>\n<p>\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0441\u043a\u0430\u044f \u043f\u0430\u043d\u0435\u043b\u044c;<\/p>\n<\/li>\n<li>\n<p>stream overlay;<\/p>\n<\/li>\n<li>\n<p>\u0447\u0430\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u043a\u0430\u0437\u044b;<\/p>\n<\/li>\n<li>\n<p>\u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u044b\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 real-time \u043e\u0442\u0432\u0430\u043b\u0438\u043b\u0441\u044f, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0441 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439.<\/p>\n<h3>\u0418\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u043e\u0432<\/h3>\n<p>Connection token \u0438 subscription token \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u043c\u0435\u044e\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438. \u042d\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e. \u0411\u0435\u0441\u0441\u0440\u043e\u0447\u043d\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b \u2014 \u0434\u043e\u0440\u043e\u0433\u0430 \u043a \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041d\u043e \u0435\u0441\u043b\u0438 \u0442\u043e\u043a\u0435\u043d \u0438\u0441\u0442\u0451\u043a, \u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u043c\u0435\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0430:<\/p>\n<pre><code>const centrifuge = new Centrifuge('wss:\/\/example.com\/connection\/websocket', {    getToken: async function () {        return await fetchConnectionToken();    },});<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0445 \u043f\u043e\u0434\u043f\u0438\u0441\u043e\u043a \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e:<\/p>\n<pre><code>const subscription = centrifuge.newSubscription(channelName, {    getToken: async function () {        return await fetchSubscriptionToken(channelName);    },});<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f subscription token:<\/p>\n<pre><code>async function fetchSubscriptionToken(channelName) {    const response = await fetch('\/api\/realtime\/subscription-token', {        method: 'POST',        credentials: 'include',        headers: {            Accept: 'application\/json',            'Content-Type': 'application\/json',        },        body: JSON.stringify({            channel: channelName,        }),    });    if (!response.ok) {        throw new Error('Failed to fetch Centrifugo subscription token.');    }    const data = await response.json();    return data.token;}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>Laravel \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0431\u044f\u0437\u0430\u043d \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043c\u043e\u0436\u0435\u0442 \u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u044d\u0442\u043e\u0442 \u043a\u0430\u043d\u0430\u043b. \u041d\u0435 frontend. \u041d\u0435 \u201c\u043c\u044b \u0436\u0435 \u0441\u043a\u0440\u044b\u043b\u0438 \u043a\u043d\u043e\u043f\u043a\u0443\u201d. \u0418\u043c\u0435\u043d\u043d\u043e backend.<\/p>\n<h3>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435 reconnect<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e.<\/p>\n<p>\u041f\u043e\u043a\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u043e\u0431\u043e\u0440\u0432\u0430\u043d\u043e, \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0433\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e reconnect \u0447\u0430\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435:<\/p>\n<pre><code>centrifuge.on('connected', async function () {    await reloadCurrentPageState();});<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code>async function reloadCurrentPageState() {    if (window.currentOrderId !== undefined) {        await reloadOrder(window.currentOrderId);    }    await reloadNotificationsCounter();}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u042d\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432, \u0433\u0434\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0431\u044b\u0441\u0442\u0440\u043e \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f:<\/p>\n<ul>\n<li>\n<p>\u0441\u0442\u0430\u0442\u0443\u0441\u044b \u043f\u043b\u0430\u0442\u0435\u0436\u0435\u0439;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0447\u0430\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>stream widgets;<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u043a\u0430\u0437\u044b;<\/p>\n<\/li>\n<li>\n<p>\u0430\u0434\u043c\u0438\u043d\u0441\u043a\u0438\u0435 \u043f\u0430\u043d\u0435\u043b\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u043c\u044b\u0441\u043b \u043f\u0440\u043e\u0441\u0442\u043e\u0439:<\/p>\n<p>WebSocket \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0443 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439, \u043d\u043e HTTP \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0438\u0441\u0442\u0438\u043d\u0443.<\/p>\n<h3>Nginx \u0438 WebSocket<\/h3>\n<p>\u041d\u0430 production WebSocket \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 Nginx. \u0415\u0441\u043b\u0438 Nginx \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, Centrifugo \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u0440\u0430\u0432\u0435\u043d, Laravel \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u0440\u0430\u0432\u0435\u043d, frontend \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u0440\u0430\u0432\u0435\u043d, \u043d\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0430\u0434\u0430\u0442\u044c.<\/p>\n<p>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 proxy \u0434\u043b\u044f WebSocket:<\/p>\n<pre><code>location \/connection\/websocket {    proxy_pass http:\/\/centrifugo:8000;    proxy_http_version 1.1;    proxy_set_header Upgrade $http_upgrade;    proxy_set_header Connection \"upgrade\";    proxy_set_header Host $host;    proxy_set_header X-Real-IP $remote_addr;    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    proxy_set_header X-Forwarded-Proto $scheme;    proxy_read_timeout 3600;    proxy_send_timeout 3600;}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041a\u0440\u0438\u0442\u0438\u0447\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b:<\/p>\n<pre><code>proxy_http_version 1.1;Upgrade;Connection \"upgrade\";\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u0439 proxy_read_timeout;\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u0439 proxy_send_timeout.<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0415\u0441\u043b\u0438 timeout \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439, \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043e\u0442\u0432\u0430\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f.<\/p>\n<h3>\u0421\u0435\u043a\u0440\u0435\u0442\u044b \u0438 API key<\/h3>\n<p>\u0421\u0435\u043a\u0440\u0435\u0442\u044b Centrifugo \u043d\u0435\u043b\u044c\u0437\u044f \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0430 frontend.<\/p>\n<p>\u041d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c:<\/p>\n<pre><code>CENTRIFUGO_TOKEN_HMAC_SECRET_KEYCENTRIFUGO_API_KEYCENTRIFUGO_ADMIN_PASSWORD<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041d\u0430 frontend \u0443\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e:<\/p>\n<pre><code>connection token;subscription token;\u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 WebSocket endpoint.<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>Laravel \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u0435\u043a\u0440\u0435\u0442\u044b \u0432\u00a0<code>.env<\/code>:<\/p>\n<pre><code>CENTRIFUGO_URL=http:\/\/centrifugo:8000CENTRIFUGO_API_KEY=some-api-keyCENTRIFUGO_TOKEN_HMAC_SECRET_KEY=some-secret<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u0432 Centrifugo \u0438\u0434\u0451\u0442 \u0441 backend-\u0430:<\/p>\n<pre><code>class CentrifugoPublisher{    public function publish(        string $channel,        array $payload,    ): void {        \/\/ HTTP API request to Centrifugo with API key.    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>Frontend \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u0418\u043d\u0430\u0447\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u043b\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0435\u0441\u043b\u0438 \u043d\u0430\u0439\u0434\u0451\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u044b\u0437\u0432\u0430\u0442\u044c publish.<\/p>\n<h3>\u041b\u043e\u0433\u0438<\/h3>\n<p>\u0412 real-time \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043d\u0443\u0436\u043d\u044b \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0442\u0440\u0438 \u0441\u043b\u043e\u044f \u043b\u043e\u0433\u043e\u0432.<\/p>\n<h4>Laravel<\/h4>\n<p>\u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e connection token;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0442\u043a\u0430\u0437 \u0432 subscription token;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044e \u0441\u043e\u0431\u044b\u0442\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0448\u0438\u0431\u043a\u0438 HTTP API Centrifugo;<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 queue job;<\/p>\n<\/li>\n<li>\n<p>\u0440\u0430\u0437\u043c\u0435\u0440 payload;<\/p>\n<\/li>\n<li>\n<p>\u0442\u0438\u043f \u0441\u043e\u0431\u044b\u0442\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u043a\u0430\u043d\u0430\u043b \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430:<\/p>\n<pre><code>Log::channel('realtime')-&gt;info('Realtime event published.', [    'event' =&gt; 'order.status_changed',    'channel' =&gt; $channel,    'orderId' =&gt; $orderId,]);<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041d\u0435 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u043a\u0440\u0435\u0442\u044b \u0438 \u0442\u043e\u043a\u0435\u043d\u044b \u0446\u0435\u043b\u0438\u043a\u043e\u043c.<\/p>\n<h4>Centrifugo<\/h4>\n<p>\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0448\u0438\u0431\u043a\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u043e\u043a;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0448\u0438\u0431\u043a\u0438 API publish;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043f\u043e \u043a\u0430\u043d\u0430\u043b\u0430\u043c;<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432;<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<\/ul>\n<h4>Frontend<\/h4>\n<p>\u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u043d\u0430 \u0441\u0442\u0430\u0440\u0442\u0435, \u0430 \u043b\u0443\u0447\u0448\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430:<\/p>\n<ul>\n<li>\n<p>\u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0448\u0438\u0431\u043a\u0430 refresh token;<\/p>\n<\/li>\n<li>\n<p>reconnect;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u0442\u0438\u043f \u0441\u043e\u0431\u044b\u0442\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0448\u0438\u0431\u043a\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 payload.<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 frontend logger:<\/p>\n<pre><code>function logRealtimeError(message, context = {}) {    console.error(message, context);    \/\/ \u041c\u043e\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 endpoint:    \/\/ fetch('\/api\/client-errors', ...)}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h3>\u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433<\/h3>\n<p>Centrifugo \u2014 \u044d\u0442\u043e \u043d\u0435 \u201c\u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f WebSocket\u201d. \u042d\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442. \u0415\u0433\u043e \u043d\u0430\u0434\u043e \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442\u044c.<\/p>\n<p>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c Centrifugo;<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439;<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u043e\u043a;<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0439;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0448\u0438\u0431\u043a\u0438 publish API;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0448\u0438\u0431\u043a\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0447\u0430\u0441\u0442\u043e\u0442\u0443 reconnect;<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 CPU\/RAM;<\/p>\n<\/li>\n<li>\n<p>\u0440\u0430\u0437\u043c\u0435\u0440 \u0438 \u0447\u0430\u0441\u0442\u043e\u0442\u0443 payload;<\/p>\n<\/li>\n<li>\n<p>\u0432\u0440\u0435\u043c\u044f \u043e\u0442\u0432\u0435\u0442\u0430 Laravel endpoint \u0434\u043b\u044f \u0442\u043e\u043a\u0435\u043d\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b:<\/p>\n<ul>\n<li>\n<p>\u0421\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043e?<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u0442\u044c \u043b\u0438 \u0432\u0441\u043f\u043b\u0435\u0441\u043a disconnect?<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u0442\u044c \u043b\u0438 \u0440\u043e\u0441\u0442 \u043e\u0448\u0438\u0431\u043e\u043a token refresh?<\/p>\n<\/li>\n<li>\n<p>\u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442\u0441\u044f \u0432 \u043c\u0438\u043d\u0443\u0442\u0443?<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435 \u0432\u044b\u0440\u043e\u0441 \u043b\u0438 payload \u0434\u043e \u043d\u0435\u043f\u0440\u0438\u043b\u0438\u0447\u043d\u044b\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432?<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435 \u0441\u0442\u0430\u043b \u043b\u0438 endpoint \u0432\u044b\u0434\u0430\u0447\u0438 \u0442\u043e\u043a\u0435\u043d\u0430 \u0443\u0437\u043a\u0438\u043c \u043c\u0435\u0441\u0442\u043e\u043c?<\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u0435\u0437 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 real-time \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0447\u0451\u0440\u043d\u044b\u0439 \u044f\u0449\u0438\u043a: \u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0445 \u0443\u0437\u043d\u0430\u0435\u0448\u044c \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u0410 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0432\u0438\u0434\u0435\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0432 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430\u0445.<\/p>\n<h3>\u0422\u0438\u043f\u0438\u0447\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438<\/h3>\n<h4>1. \u0421\u0447\u0438\u0442\u0430\u0442\u044c WebSocket \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u0438\u0441\u0442\u0438\u043d\u044b<\/h4>\n<p>\u0421\u043e\u0431\u044b\u0442\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430. \u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0443\u0436\u043d\u043e \u0443\u043c\u0435\u0442\u044c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 HTTP.<\/p>\n<h4>2. \u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 payload<\/h4>\n<p>WebSocket \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u043c\u0435\u043d\u044f\u0442\u044c REST API. \u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f.<\/p>\n<h4>3. \u041d\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c token<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0442\u043e\u043a\u0435\u043d\u044b \u0438\u0441\u0442\u0435\u043a\u0430\u044e\u0442, \u043d\u043e \u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0435 \u0443\u043c\u0435\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435, real-time \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0443\u043c\u0438\u0440\u0430\u0442\u044c.<\/p>\n<h4>4. \u041d\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c reconnect<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435 reconnect \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0430 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0430\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0432\u0435\u0440\u043d\u0443\u043b\u043e\u0441\u044c.<\/p>\n<h4>5. \u0421\u0432\u0435\u0442\u0438\u0442\u044c \u0441\u0435\u043a\u0440\u0435\u0442\u044b Centrifugo \u043d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0435<\/h4>\n<p>API key \u0438 secret \u0434\u043e\u043b\u0436\u043d\u044b \u0436\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 backend-\u0435.<\/p>\n<h4>6. \u041d\u0435 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 publish<\/h4>\n<p>\u0415\u0441\u043b\u0438 Laravel \u043d\u0435 \u0441\u043c\u043e\u0433 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u044d\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432\u0438\u0434\u043d\u043e. \u0418\u043d\u0430\u0447\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043c\u043e\u043b\u0447\u0430 \u043d\u0435 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u0441\u044f.<\/p>\n<h4>7. \u041d\u0435 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442\u044c Centrifugo<\/h4>\n<p>Centrifugo \u043d\u0443\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043a\u0430\u043a production-\u0441\u0435\u0440\u0432\u0438\u0441 \u0441 \u043b\u043e\u0433\u0430\u043c\u0438.<\/p>\n<h3>\u0412\u044b\u0432\u043e\u0434<\/h3>\n<p>\u0424\u0440\u043e\u043d\u0442\u0435\u043d\u0434 \u0438 \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u044f \u0432 Laravel + Centrifugo \u2014 \u044d\u0442\u043e \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 real-time \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<\/p>\n<p>Backend \u043c\u043e\u0436\u0435\u0442 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f. Centrifugo \u043c\u043e\u0436\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u041d\u043e \u0435\u0441\u043b\u0438 frontend \u043d\u0435 \u0443\u043c\u0435\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f, \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u044b \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 HTTP, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441.<\/p>\n<p>\u041d\u0430\u0434\u0451\u0436\u043d\u0430\u044f real-time \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0441\u0442\u0440\u043e\u0438\u0442\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435:<\/p>\n<p>WebSocket \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0439 \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439, HTTP \u2014 \u0434\u043b\u044f \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u0441\u0442\u0438\u043d\u044b.<\/p>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1036458\/\">https:\/\/habr.com\/ru\/articles\/1036458\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Real-time \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0435 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0442\u043e\u043c, \u0447\u0442\u043e backend \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432 Centrifugo. \u042d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u044b. \u0412\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0435 \u0438 \u0432 \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u0438: \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u043f\u043e\u0442\u0435\u0440\u044f \u0441\u0435\u0442\u0438, \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f, Nginx, \u0441\u0435\u043a\u0440\u0435\u0442\u044b, \u043b\u043e\u0433\u0438 \u0438 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433.\u041d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0440\u0430\u0441\u0438\u0432\u043e: \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b\u043e\u0441\u044c, WebSocket \u043f\u043e\u043b\u0443\u0447\u0438\u043b payload, \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043e\u0431\u043d\u043e\u0432\u0438\u043b\u0441\u044f. \u041f\u043e\u0442\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432 production, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043d\u043e\u0443\u0442\u0431\u0443\u043a \u043f\u043e\u0441\u043b\u0435 \u0441\u043d\u0430, \u0441\u0435\u0442\u044c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0441 Wi-Fi \u043d\u0430 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u0443\u044e, \u0442\u043e\u043a\u0435\u043d \u0438\u0441\u0442\u0435\u043a\u0430\u0435\u0442, Nginx \u0440\u0435\u0436\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435, Centrifugo \u043f\u0438\u0448\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, frontend \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442. \u0418 \u0432\u043e\u0442 \u0443\u0436\u0435 real-time \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u201c\u0438\u043d\u043e\u0433\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0441\u0430\u043c \u043e\u0436\u0438\u0432\u0430\u0435\u0442, \u0438\u043d\u043e\u0433\u0434\u0430 \u043d\u0435\u0442\u201d.\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u0437\u0430 \u0447\u0442\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434 \u0432 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 Laravel + Centrifugo, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 Centrifuge JS client \u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u044f WebSocket-\u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0435 \u0432\u0442\u043e\u0440\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c, \u0430 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u0443\u0441\u043f\u0435\u0445\u0430.\u0412 production real-time \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0432\u0430\u0436\u043d\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u043d\u043e \u0438:\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c frontend \u0447\u0435\u0440\u0435\u0437 Centrifuge JS client;\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438;\u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u044b\u0432\u0430 \u0441\u0435\u0442\u0438;\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c connection token \u0438 subscription token;\u043d\u0435 \u0441\u0447\u0438\u0442\u0430\u0442\u044c WebSocket \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u0438\u0441\u0442\u0438\u043d\u044b;\u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441;\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c Nginx;\u043d\u0435 \u0441\u0432\u0435\u0442\u0438\u0442\u044c \u0441\u0435\u043a\u0440\u0435\u0442\u044b \u0438 API key \u043d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0435;\u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438;\u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442\u044c Centrifugo \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u043c\u044b\u0441\u043b\u044c:WebSocket \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u043d\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0443\u043c\u0435\u0442\u044c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0447\u0435\u0440\u0435\u0437 HTTP.\u0413\u0434\u0435 frontend \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 Laravel + Centrifugo\u0412 \u0442\u0438\u043f\u043e\u0432\u043e\u0439 \u0441\u0445\u0435\u043c\u0435 \u0440\u043e\u043b\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u0430\u043a:\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 Laravel + Centrifugo + Frontend \u0434\u043b\u044f real-time \u0441\u0438\u0441\u0442\u0435\u043c\u044bFrontend \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0430\u043c \u0440\u0435\u0448\u0430\u0442\u044c \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0443. \u041e\u043d \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043f\u0440\u0430\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0447\u0443\u0436\u0438\u043c \u043a\u0430\u043d\u0430\u043b\u0430\u043c. \u041e\u043d \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u043d\u0430\u0442\u044c \u0441\u0435\u043a\u0440\u0435\u0442 Centrifugo. \u0415\u0433\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u043e\u0449\u0435 \u0438 \u0441\u0442\u0440\u043e\u0436\u0435: \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f, \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f, \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c UI \u0438 \u043f\u0440\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0445 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435.\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 Centrifuge JS client\u041d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0435 \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 JavaScript-\u043a\u043b\u0438\u0435\u043d\u0442 Centrifugo \u2014\u00a0centrifuge.\u041f\u0440\u0438\u043c\u0435\u0440 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f:import { Centrifuge } from &#8216;centrifuge&#8217;;const centrifuge = new Centrifuge(&#8216;wss:\/\/example.com\/connection\/websocket&#8217;, {    token: connectionToken,});centrifuge.connect();connectionToken\u00a0frontend \u043d\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u0430\u043c. \u041e\u043d \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u0435\u0433\u043e \u0443 Laravel:async function fetchConnectionToken() {    const response = await fetch(&#8216;\/api\/realtime\/connection-token&#8217;, {        credentials: &#8216;include&#8217;,        headers: {            Accept: &#8216;application\/json&#8217;,        },    });    if (!response.ok) {        throw new Error(&#8216;Failed to fetch Centrifugo connection token.&#8217;);    }    const data = await response.json();    return data.token;}\u0417\u0434\u0435\u0441\u044c \u0432\u0430\u0436\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442: frontend \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 token \u043e\u0442 backend, \u0430 \u043d\u0435 \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u0435\u043a\u0440\u0435\u0442\u044b Centrifugo.\u0421\u0435\u043a\u0440\u0435\u0442\u044b \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435. \u041d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442 \u0443\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u0439 JWT, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.\u041f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 \u043d\u0430 \u043a\u0430\u043d\u0430\u043b\u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u0430\u043d\u0430\u043b.\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u0430\u043d\u0430\u043b:const subscription = centrifuge.newSubscription(`user:${userId}`);subscription.on(&#8216;publication&#8217;, function (context) {    handleRealtimePublication(context.data);});subscription.on(&#8216;subscribed&#8217;, function () {    console.log(&#8216;Subscribed to user channel.&#8217;);});subscription.on(&#8216;error&#8217;, function (context) {    console.error(&#8216;Subscription error.&#8217;, context);});subscription.subscribe();\u0415\u0441\u043b\u0438 \u043a\u0430\u043d\u0430\u043b \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0439, subscription token \u0442\u043e\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f backend-\u043e\u043c.\u041f\u0440\u0438\u043c\u0435\u0440:const subscription = centrifuge.newSubscription(`private:user:${userId}`, {    token: subscriptionToken,});\u0418 \u0441\u043d\u043e\u0432\u0430:\u00a0subscriptionToken\u00a0\u0432\u044b\u0434\u0430\u0451\u0442 Laravel. \u0424\u0440\u043e\u043d\u0442\u0435\u043d\u0434 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u0430\u043c \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0447\u0443\u0436\u043e\u0439 \u043a\u0430\u043d\u0430\u043b.\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0439\u0421\u0430\u043c\u0430\u044f \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u2014 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u043e frontend \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 payload.\u041f\u043b\u043e\u0445\u043e\u0439 payload:{    &#171;id&#187;: 123,    &#171;user&#187;: {        &#171;id&#187;: 10,        &#171;name&#187;: &#171;Max&#187;,        &#171;email&#187;: &#171;max@example.com&#187;,        &#171;roles&#187;: [&#171;admin&#187;],        &#171;settings&#187;: {}    },    &#171;order&#187;: {        &#171;id&#187;: 456,        &#171;items&#187;: [],        &#171;payments&#187;: [],        &#171;history&#187;: []    }}\u0422\u0430\u043a\u043e\u0439 payload \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 WebSocket \u0432 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 REST API. \u041f\u043e\u0442\u043e\u043c \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c\u044e, \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u0432\u0435\u0440\u0441\u0438\u044f\u043c\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0430.\u0425\u043e\u0440\u043e\u0448\u0438\u0439 payload \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439:{    &#171;type&#187;: &#171;order.status_changed&#187;,    &#171;id&#187;: 456,    &#171;status&#187;: &#171;paid&#187;}\u0438\u043b\u0438:{    &#171;type&#187;: &#171;notification.created&#187;,    &#171;id&#187;: 987}Frontend \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438 \u0440\u0435\u0448\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c:function handleRealtimePublication(payload) {    switch (payload.type) {        case &#8216;order.status_changed&#8217;:            updateOrderStatus(payload.id, payload.status);            return;        case &#8216;notification.created&#8217;:            incrementNotificationsCounter();            return;        default:            console.warn(&#8216;Unknown realtime event type.&#8217;, payload);    }}switch\u00a0\u0437\u0434\u0435\u0441\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u0435\u043d. \u042d\u0442\u043e \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0435, \u0430 \u043d\u0435 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430 \u043d\u0430 300 \u0441\u0442\u0440\u043e\u043a. \u0415\u0441\u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0441\u0442\u0430\u043d\u0435\u0442 \u043c\u043d\u043e\u0433\u043e, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 map \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432.const handlers = {    &#8216;order.status_changed&#8217;: handleOrderStatusChanged,    &#8216;notification.created&#8217;: handleNotificationCreated,};function handleRealtimePublication(payload) {    const handler = handlers[payload.type];    if (handler === undefined) {        console.warn(&#8216;Unknown realtime event type.&#8217;, payload);        return;    }    handler(payload);}\u0422\u0430\u043a \u043a\u043e\u0434 \u043f\u0440\u043e\u0449\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c.WebSocket \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u0438\u0441\u0442\u0438\u043d\u044b\u042d\u0442\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442.WebSocket-\u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u043f\u0440\u0438\u0439\u0442\u0438:\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0442\u0435\u0440\u044f\u043b \u0441\u0435\u0442\u044c;\u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0443\u0448\u0451\u043b \u0432 sleep;\u043d\u043e\u0443\u0442\u0431\u0443\u043a \u043f\u0440\u043e\u0441\u043d\u0443\u043b\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0447\u0430\u0441;\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u043e\u0440\u0432\u0430\u043b\u043e\u0441\u044c;\u0442\u043e\u043a\u0435\u043d \u0438\u0441\u0442\u0451\u043a;\u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 \u043d\u0435 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0430\u0441\u044c;\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0448\u043b\u043e \u0440\u0430\u043d\u044c\u0448\u0435, \u0447\u0435\u043c frontend \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043b \u043d\u0443\u0436\u043d\u044b\u0439 state.\u041f\u043e\u044d\u0442\u043e\u043c\u0443 real-time \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043b\u0443\u0447\u0448\u0435 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043a\u0430\u043a \u0441\u0438\u0433\u043d\u0430\u043b:\u0447\u0442\u043e-\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c;\u043e\u0431\u043d\u043e\u0432\u0438 \u0447\u0430\u0441\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430;\u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 HTTP.\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:async function handleOrderStatusChanged(payload) {    if (currentOrderId !== payload.id) {        return;    }    await reloadOrder(payload.id);}async function reloadOrder(orderId) {    const response = await fetch(`\/api\/orders\/${orderId}`, {        credentials: &#8216;include&#8217;,        headers: {            Accept: &#8216;application\/json&#8217;,        },    });    if (!response.ok) {        throw new Error(&#8216;Failed to reload order.&#8217;);    }    const order = await response.json();    renderOrder(order);}\u0418\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c UI \u043f\u0440\u044f\u043c\u043e \u0438\u0437 payload. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0447\u0451\u0442\u0447\u0438\u043a \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439. \u041d\u043e \u0434\u043b\u044f \u0432\u0430\u0436\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043b\u0443\u0447\u0448\u0435 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 HTTP.\u041f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u0442\u0435\u0440\u044f \u0441\u0435\u0442\u0438Centrifuge JS client \u0443\u043c\u0435\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f, \u043d\u043e frontend \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u043b\u0443\u0448\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f:centrifuge.on(&#8216;connecting&#8217;, function (context) {    console.log(&#8216;Connecting to Centrifugo.&#8217;, context);    showRealtimeStatus(&#8216;connecting&#8217;);});centrifuge.on(&#8216;connected&#8217;, function (context) {    console.log(&#8216;Connected to Centrifugo.&#8217;, context);    showRealtimeStatus(&#8216;connected&#8217;);});centrifuge.on(&#8216;disconnected&#8217;, function (context) {    console.warn(&#8216;Disconnected from Centrifugo.&#8217;, context);    showRealtimeStatus(&#8216;disconnected&#8217;);});\u0414\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0439 \u043a\u0440\u0430\u0441\u043d\u044b\u0439 \u0431\u0430\u043d\u043d\u0435\u0440. \u041d\u043e \u0434\u043b\u044f \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u0441\u0442\u0430\u0442\u0443\u0441 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0432\u0430\u0436\u0435\u043d.\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u0430\u0431\u0438\u043d\u0435\u0442 \u0441 \u043f\u043b\u0430\u0442\u0435\u0436\u0430\u043c\u0438;\u0430\u0434\u043c\u0438\u043d\u043a\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438;\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0441\u043a\u0430\u044f \u043f\u0430\u043d\u0435\u043b\u044c;stream overlay;\u0447\u0430\u0442;\u0437\u0430\u043a\u0430\u0437\u044b;\u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u044b\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u044b.\u0415\u0441\u043b\u0438 real-time \u043e\u0442\u0432\u0430\u043b\u0438\u043b\u0441\u044f, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0441 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439.\u0418\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u043e\u0432Connection token \u0438 subscription token \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u043c\u0435\u044e\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438. \u042d\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e. \u0411\u0435\u0441\u0441\u0440\u043e\u0447\u043d\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b \u2014 \u0434\u043e\u0440\u043e\u0433\u0430 \u043a \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438.\u041d\u043e \u0435\u0441\u043b\u0438 \u0442\u043e\u043a\u0435\u043d \u0438\u0441\u0442\u0451\u043a, \u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u043c\u0435\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439.\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0430:const centrifuge = new Centrifuge(&#8216;wss:\/\/example.com\/connection\/websocket&#8217;, {    getToken: async function () {        return await fetchConnectionToken();    },});\u0414\u043b\u044f \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0445 \u043f\u043e\u0434\u043f\u0438\u0441\u043e\u043a \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e:const subscription = centrifuge.newSubscription(channelName, {    getToken: async function () {        return await fetchSubscriptionToken(channelName);    },});\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f subscription token:async function fetchSubscriptionToken(channelName) {    const response = await fetch(&#8216;\/api\/realtime\/subscription-token&#8217;, {        method: &#8216;POST&#8217;,        credentials: &#8216;include&#8217;,        headers: {            Accept: &#8216;application\/json&#8217;,            &#8216;Content-Type&#8217;: &#8216;application\/json&#8217;,        },        body: JSON.stringify({            channel: channelName,        }),    });    if (!response.ok) {        throw new Error(&#8216;Failed to fetch Centrifugo subscription token.&#8217;);    }    const data = await response.json();    return data.token;}Laravel \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0431\u044f\u0437\u0430\u043d \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043c\u043e\u0436\u0435\u0442 \u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u044d\u0442\u043e\u0442 \u043a\u0430\u043d\u0430\u043b. \u041d\u0435 frontend. \u041d\u0435 \u201c\u043c\u044b \u0436\u0435 \u0441\u043a\u0440\u044b\u043b\u0438 \u043a\u043d\u043e\u043f\u043a\u0443\u201d. \u0418\u043c\u0435\u043d\u043d\u043e backend.\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435 reconnect\u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e.\u041f\u043e\u043a\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u043e\u0431\u043e\u0440\u0432\u0430\u043d\u043e, \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0433\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e reconnect \u0447\u0430\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435:centrifuge.on(&#8216;connected&#8217;, async function () {    await reloadCurrentPageState();});\u041f\u0440\u0438\u043c\u0435\u0440:async function reloadCurrentPageState() {    if (window.currentOrderId !== undefined) {        await reloadOrder(window.currentOrderId);    }    await reloadNotificationsCounter();}\u042d\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432, \u0433\u0434\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0431\u044b\u0441\u0442\u0440\u043e \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f:\u0441\u0442\u0430\u0442\u0443\u0441\u044b \u043f\u043b\u0430\u0442\u0435\u0436\u0435\u0439;\u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438;\u0447\u0430\u0442;\u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f;stream widgets;\u0437\u0430\u043a\u0430\u0437\u044b;\u0430\u0434\u043c\u0438\u043d\u0441\u043a\u0438\u0435 \u043f\u0430\u043d\u0435\u043b\u0438.\u0421\u043c\u044b\u0441\u043b \u043f\u0440\u043e\u0441\u0442\u043e\u0439:WebSocket \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0443 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439, \u043d\u043e HTTP \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0438\u0441\u0442\u0438\u043d\u0443.Nginx \u0438 WebSocket\u041d\u0430 production WebSocket \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 Nginx. \u0415\u0441\u043b\u0438 Nginx \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, Centrifugo \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u0440\u0430\u0432\u0435\u043d, Laravel \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u0440\u0430\u0432\u0435\u043d, frontend \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u0440\u0430\u0432\u0435\u043d, \u043d\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0430\u0434\u0430\u0442\u044c.\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 proxy \u0434\u043b\u044f WebSocket:location \/connection\/websocket {    proxy_pass http:\/\/centrifugo:8000;    proxy_http_version 1.1;&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-480129","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/480129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=480129"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/480129\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=480129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=480129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=480129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}