{"id":14974445,"url":"https://github.com/matviib/notifier","last_synced_at":"2025-10-27T09:30:25.086Z","repository":{"id":62525332,"uuid":"117981994","full_name":"MatviiB/notifier","owner":"MatviiB","description":"NO LIBRARIES socket per page bridge for your Laravel application. (CLIENT PART INCLUDED)","archived":false,"fork":false,"pushed_at":"2019-01-08T20:53:02.000Z","size":140,"stargazers_count":62,"open_issues_count":0,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-01T04:31:38.030Z","etag":null,"topics":["composer-library","composer-package","laravel","laravel-5","laravel-5-package","laravel-application","laravel5","laravel55","notifications","notifier","real-time","socket","socket-client","socket-communication","socket-programming","socket-server","sockets","sockets-easy","socketserver","socketstream"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MatviiB.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-18T12:48:35.000Z","updated_at":"2024-02-07T22:19:19.000Z","dependencies_parsed_at":"2022-11-02T14:01:21.463Z","dependency_job_id":null,"html_url":"https://github.com/MatviiB/notifier","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatviiB%2Fnotifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatviiB%2Fnotifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatviiB%2Fnotifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatviiB%2Fnotifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MatviiB","download_url":"https://codeload.github.com/MatviiB/notifier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238471950,"owners_count":19478134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composer-library","composer-package","laravel","laravel-5","laravel-5-package","laravel-application","laravel5","laravel55","notifications","notifier","real-time","socket","socket-client","socket-communication","socket-programming","socket-server","sockets","sockets-easy","socketserver","socketstream"],"created_at":"2024-09-24T13:50:34.466Z","updated_at":"2025-10-27T09:30:24.721Z","avatar_url":"https://github.com/MatviiB.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp\u003e\n  \u003cimg src=\"https://scrutinizer-ci.com/g/MatviiB/notifier/badges/build.png?b=master\" alt=\"build passed\"\u003e\n  \u003cimg src=\"https://scrutinizer-ci.com/g/MatviiB/notifier/badges/code-intelligence.svg?b=master\" alt=\"code-intelligence\"\u003e\n  \u003cimg src=\"https://poser.pugx.org/matviib/notifier/license\" alt=\"license\"\u003e\n  \u003cimg src=\"https://poser.pugx.org/matviib/notifier/downloads\" alt=\"downloads\"\u003e\n\u003c/p\u003e\n\n### Base concepts\n\nYou don't need socket.io, pusher.js, jQuery, bootstrap, node.js, vue.js to start using this package.\n\nThis package can be used for sending data synchronously to each user.\n\nThis package sends data ONLY to named routes declared as `GET`.\n\nYou will get your own socket server on back-end and your clients will connect to it directly, without any third-party requests to be send.\n\nYou will have pretty notifications from scratch.\n\nTo view available routes you can run `php artisan notifier:init show` command. It will display available routes in the table and initiate the socket server.\n\n| Code | Description |\n| --- | --- |\n| `event(new Notify($data));` | - send to all routes. |\n| `event(new Notify($data, $routes));` |- send to routes in `$routes` array. |\n| `event(new Notify($data, $routes, $users));` | - send to routes in `$routes` and only to users in `$users`.|\n\n### Installation\n\n```\ncomposer require matviib/notifier\n```\n\nFor Laravel \u003c 5.5 add provider to config/app.php\n```php\nMatviiB\\Notifier\\NotifierServiceProvider::class,\n```\n\nFor publish notifier config file and js file for notifications out of the box:\n```sh\nphp artisan vendor:publish\n```\nand choose \"Provider: MatviiB\\Notifier\\NotifierServiceProvider\" if requested.\n\n### Starting server\n\nAdd worker daemon for ```php artisan notifier:init``` process with Supervisor,\n\nOR\n\nJust run ```php artisan notifier:init``` in terminal.\n\nIf you use SSL you need add to your `nginx` configuration file to server block:\n```\n    location /websocket {\n        proxy_pass http://\u003cyour-domain\u003e:\u003cport\u003e; #server host and port\n        proxy_http_version 1.1;\n        proxy_set_header Upgrade $http_upgrade;\n        proxy_set_header Connection \"Upgrade\";\n\n        # Timeout configuration.\n        proxy_redirect off;\n        proxy_connect_timeout  300;\n        proxy_send_timeout     300;\n        proxy_read_timeout     300;\n   }\n```\n### Usage\n\nAt first you need to add `@include('notifier::connect')` before using `socket.addEventListener()` in your view or main layout to use it on ALL pages.\n\nIf you want use notifications from the scratch you need to add `@include('notifier::connect_and_show')` to the view.\n\nAnywhere in your back-end add next event:\n\n`event(new Notify($data));`\n\nOn front-end part add event listener\n```\n\u003cscript\u003e\n    socket.addEventListener('message', function (event) {\n        console.log('Message from server', event.data);\n    });\n\u003c/script\u003e\n```\n\n### Use built-in notifications.\n\nBuilt-in notifications is a vue.js with [vue-notifications](https://github.com/euvl/vue-notification) plugin. If you already use vue.js in application you can just add this plugin yourself.\n\n##### Mapping `$data` parameter.\n\n| Parameter | Description |\n| --- | --- |\n| `'note' =\u003e 1,` | - use notes `true` |\n| `'type' =\u003e 'warn|success|error|info',` | - type of note |\n| `'title' =\u003e 'TEXT'` | - title of the note |\n| `'text' =\u003e 'Lorem ipsum'` | - note's body |\n\n##### Positioning.\nIn `config/notifier.php` you can modify position where notifications will be shown.\n\n```\n// Horizontal options: left, center, right\n// Vertical options: top, bottom\n'position' =\u003e [\n        'vertical' =\u003e 'bottom',\n        'horizontal' =\u003e 'right'\n    ]\n```\n\n## Security\n\nThis package allows one way messages - only from server to client.\n\nAll messages from client after connecting will be ignored.\n\nFrom server side messages protected with socket_pass parameter from notifier config.\n\nChannels to users protected with unique hash.\n\n\n## Example with charts\n\nAfter installation add to web.php\n```\nRoute::get('chart', function () {\n    return view('chart');\n})-\u003ename('chart');\n```\ncreate view `/resources/views/chart.blade.php`\n\n```\n\u003c!doctype html\u003e\n\u003chtml lang=\"{{ app()-\u003egetLocale() }}\"\u003e\n\u003chead\u003e\n    \u003cmeta charset=\"utf-8\"\u003e\n    \u003cmeta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\"\u003e\n\n    \u003ctitle\u003eChart\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003ccanvas id=\"myChart\"\u003e\u003c/canvas\u003e\n@include('notifier::connect')\n\u003cscript src=\"https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\"\u003e\n\n    var data = [12, 19, 3, 17, 6, 3, 7, 45, 60, 25];\n\n    var myChart = new Chart(document.getElementById('myChart'), {\n        type: 'line',\n        data: {\n            labels: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\n            datasets: [{\n                label: 'example',\n                data: data\n            }]\n        }\n    });\n\n    socket.addEventListener('message', function (event) {\n        myChart.data.datasets[0].data.splice(0, 1);\n        myChart.data.datasets[0].data.push(JSON.parse(event.data).data.value);\n        myChart.update();\n    });\n\u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\nIn .env fix your APP_URL `APP_URL=http://\u003c\u003cU APP URL\u003e\u003e`\n\nCreate test command `php artisan make:command Test`\n```\nuse MatviiB\\Notifier\\Events\\Notify; \n\n...\n\nprotected $signature = 'test';\n\npublic function handle()\n    {\n        while ($i \u003c 100) {\n            $value = random_int(10, 100);\n            $data['value'] = $value;\n            event(new Notify($data, ['chart']));\n            usleep(rand(100000, 500000));\n        }\n}\n```\nRun: `php artisan notifier:init`\n\nRun in another shell:  `php artisan test`\n\nOpen `/chart` page.\n\n### Usage Example\nSend new values to chart on some page synchronously to each user:\n\n`event(new Notify($data, ['chart']));`\n\nOr to users with `id` 3 and 5: `event(new Notify($data, ['chart'], [3, 5]));`\n\n![laravel socket server](https://gitlab.com/MatviiB/assets/raw/master/ezgif.com-video-to-gif.gif)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatviib%2Fnotifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatviib%2Fnotifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatviib%2Fnotifier/lists"}