cednore/boom-controller

Booming server control interface for Laravel

1.0.0 2022-04-11 19:11 UTC

This package is auto-updated.

Last update: 2024-05-11 23:51:38 UTC


README

Booming server control interface for Laravel

❗ IMPORTANT: This project is not actively maintained.

boom-controller is a composer package for Laravel applications to control boom-server microservice.

See boom-demo for example usage of this project.

Currently, this project supports only socket.io:^2.2.0, laravel:^5.7|^6.0 and php:^7|^8.

Features

  1. Expose endpoints to listen socket.io events coming from frontend clients
  2. PHP class to provide same interface as socket.io's Node.js server (for easy porting of legacy applications)
  3. Facade for smooth syntax
  4. Authentication of traffic between boom-server and API
  5. State machine over MySQL table to share list of sockets

Installation

# Install cednore/boom-controller package
composer require cednore/boom-controller

# Create config, route and default controller for root namespace
php artisan boom:init

# Start development server
php artisan serve

Emit cheatsheet (comparison between legacy JavaScript syntax and new PHP syntax)

Basic emit

socket.emit(/* ... */);
$request->socket->emit(/* ... */);

To all clients in the current namespace except the sender

socket.broadcast.emit(/* ... */);
$request->socket->broadcast->emit(/* ... */);

To all clients in room1 except the sender

socket.to('room1').emit(/* ... */);
$request->socket->to('room1')->emit(/* ... */);

To all clients in room1 and/or room2 except the sender

socket.to('room1').to('room2').emit(/* ... */);
$request->socket->to('room1')->to('room2')->emit(/* ... */);

To all clients in room1

io.in('room1').emit(/* ... */);
use Boom\Facades\Boom as IO;
IO::in('room1')->emit(/* ... */);

To all clients in namespace "myNamespace"

io.of('myNamespace').emit(/* ... */);
use Boom\Facades\Boom as IO;
IO::of('myNamespace')->emit(/* ... */);

To all clients in room1 in namespace "myNamespace"

io.of('myNamespace').to('room1').emit(/* ... */);
use Boom\Facades\Boom as IO;
IO::of('myNamespace')->to('room1')->emit(/* ... */);

To individual socketid (private message)

io.to(socketId).emit(/* ... */);
use Boom\Facades\Boom as IO;
IO::to($socketId)->emit(/* ... */);

To all clients on this node (when using multiple nodes)

io.local.emit(/* ... */);
use Boom\Facades\Boom as IO;
IO::$local->emit(/* ... */);

To all connected clients

io.emit(/* ... */);
use Boom\Facades\Boom as IO;
IO::emit(/* ... */);

Without compression

socket.compress(false).emit(/* ... */);
$request->socket->compress(false)->emit(/* ... */);

A message that might be dropped if the low-level transport is not writable

socket.volatile.emit(/* ... */);
$request->socket->volatile->emit(/* ... */);

Configuration

The file config/boom.php contains an array of configurations. See code comments inside this file for detailed explanations.

Artisan commands

Command: boom:init

Initialize boom controller.

Usage:

php artisan boom:init [options]

Options:

--force  Overwrite any existing files.

Command: boom:make:nsp

Make a new socket.io namespace handler.

Usage:

php artisan boom:make:nsp [options] [--] <name>

Arguments:

name  Name of new namespace to create.

Options:

--force  Overwrite any existing files.

Cloning

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See Installation chapter for notes on how to use this project on a live system.

# Clone this repo
git clone git@github.com:cednore/boom-controller.git
cd boom-controller

Project roadmaps

  1. Testing desperately needed ;-)
  2. Resourceful documentation; Changelog, contribution guide, issue/PR templates, GitHub releases, dedicated documentation website
  3. Version compatibility check between boom-controller and boom-server
  4. CI/CD pipelines for building, testing and publishing
  5. Support higher socket.io and laravel versions
  6. More smooth controller syntax
  7. Detailed error handling
  8. Memcached driver
  9. More stable db connection
  10. Dockerization of microservice
  11. Combine boom-server and boom-controller in a single monorepo

License

This project is licensed under the MIT license. See full contents at LICENSE file.