Websocket server for laravel
npm install larasopp-serverlarasopp-server is a Node.js WebSocket server designed specifically for Laravel applications. It provides bidirectional communication between clients and server, supports channels, user authentication, and connection management.
larasopp/larasopp package
bash
npm i larasopp-server -g
`
$3
`bash
npm i larasopp-server
`
$3
`bash
npx larasopp-server start
`
Running
After installation, start the server with:
`bash
larasopp-server start
`
or with npx:
`bash
npx larasopp-server start
`
Configuration
Create a larasopp-server.json file in the project root or in the directory from which the server is started.
$3
`json
{
"appHost": "http://127.0.0.1:8000",
"key": "your-secret-key-here",
"host": "0.0.0.0",
"port": 3001,
"debug": true,
"log": true,
"logPath": "./",
"ssl": {
"cert": "/path/to/certificate.crt",
"key": "/path/to/private.key",
"ca": "/path/to/ca.crt"
}
}
`
$3
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| appHost | string | Yes | URL of your Laravel application (e.g., http://127.0.0.1:8000) |
| key | string | Yes | Secret key for server management via control channel |
| host | string | No | Host to listen on (default: 0.0.0.0) |
| port | number | Yes | Port for WebSocket connections (default: 3001) |
| debug | boolean | No | Enable debug mode (default: false) |
| log | boolean | No | Enable file logging (default: false) |
| logPath | string | No | Path to log directory (default: ./) |
| ssl | object | No | SSL/TLS configuration for secure connections |
$3
To enable SSL/TLS connections, add the ssl section to the configuration:
`json
{
"ssl": {
"cert": "/path/to/certificate.crt",
"key": "/path/to/private.key",
"ca": "/path/to/ca.crt"
}
}
`
Related Packages
$3
`bash
npm install larasopp
`
Documentation: https://www.npmjs.com/package/larasopp
$3
`bash
composer require larasopp/larasopp
`
Development
$3
`bash
git clone
cd larasopp-nodejs
`
$3
`bash
npm install
`
$3
`bash
npm run build
`
$3
`bash
npm start
`
Architecture
The server is built on the following components:
- Server - main server class, manages WebSocket connections
- Client - client class, handles authentication and messages
- Channel - channel and subscription management
- Core - base class with common functionality
- Http - HTTP client for interacting with Laravel API
- Config - configuration management
Security
- Use a strong secret key (key`) to protect the control channel