2017 © Pedro Peláez
 

library sc-php

SocketCluster - PHP library for interacting with the SocketCluster.io

image

soleon/sc-php

SocketCluster - PHP library for interacting with the SocketCluster.io

  • Wednesday, July 27, 2016
  • by moura137
  • Repository
  • 1 Watchers
  • 10 Stars
  • 3,122 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 4 Versions
  • 25 % Grown

The README.md

SocketCluster - PHP

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version License, (*1)

PHP library for interacting with the SocketCluster.io

It's an unofficial client php for SocketCluster (Is an open source realtime WebSocket framework for Node.js from socketcluster.io for PHP 5.5.9+)., (*2)

Contents

Installation

You can install this package by simply run this composer command:, (*3)

composer require soleon/sc-php

Usage Basic


$optionsOrUri = 'wss://localhost:443/socketcluster/?servicekey=abc' OR $optionsOrUri = [ 'secure' => true, 'host' => 'localhost', 'port' => '443', 'path' => '/socketcluster/', 'query' => [ 'servicekey' => 'abc' ], ]; $websocket = \SocketCluster\WebSocket::factory($optionsOrUri); $socket = new \SocketCluster\SocketCluster($websocket); // Event Emit $data = ['message' => 'FooBar']; $socket->publish('CHANNEL_NAME', $data);

Integrations

Laravel Framework

Then, add this service provider in your providers array [app/config/app.php]:, (*4)

SocketCluster\Providers\LaravelServiceProvider::class,

Then, add this Facade to your aliases array [app/config/app.php]:, (*5)

'SocketCluster' => SocketCluster\Laravel\SCFacade::class

Next you have to copy the configuration to your connections array [app/config/broadcasting.php]:, (*6)

/*
 * Set default broadcasting driver to socketcluster
 */
'default' => env('BROADCAST_DRIVER', 'socketcluster'),

'socketcluster' => [
    'driver' => 'socketcluster',
    'options' => [
      'secure' => true,
      'host' => 'localhost',
      'port' => '443',
      'path' => '/socketcluster/',
      'query' => [],
    ],
]

Usage Laravel, (*7)

  • With Facade
SocketCluster::publish('ChannelName', ['message' => 'Test publish!!']);

With Event Listener, (*8)

Add a custom broadcast event to your application example [app/events/PublishToSocketClusterEvent.php]:, (*9)

namespace App\Events;

use App\Events\Event;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class PublishToSocketClusterEvent implements ShouldBroadcast
{
    use SerializesModels

    /**
     * Content Message
     * @var string
     */
    public $message;

    /**
     * Construct Event
     * @param string $message
     */
    public function __construct($message)
    {
        $this->message = $message;
    }

    /**
     * Get the channels the event should broadcast on.
     * @return array
     */
    public function broadcastOn()
    {
        return ['channelName'];
    }

    /**
     * Get the data to send.
     * @return array
     */
    public function broadcastWith()
    {
      return [
        'message' => $this->message
      ]
    }
}

Now to publish in your application simply fire the event:, (*10)

event(new App\Events\PublishToSocketClusterEvent('Test publish!!'));

Pimple

Pimple is a simple PHP Dependency Injection Container, (*11)

Examples of frameworks that use: Silex, Slim, (*12)

Registering this service provider, (*13)

$app->register(new SocketCluster\Providers\PimpleServiceProvider(), array(
    'socketcluster.options' => array(
      'secure' => true,
      'host' => 'localhost',
      'port' => '443',
      'path' => '/socketcluster/',
      'query' => [],
    )
));

Usage Pimple, (*14)

$app['socketcluster']->publish('CHANNEL_NAME', $data);

Contribution

Support follows PSR-2 and PSR-4 PHP coding standards, and semantic versioning. Fork this project and make a pull request!, (*15)

License

This project is free software distributed under the terms of the MIT License., (*16)

The Versions

27/07 2016

dev-master

9999999-dev https://github.com/soleon-leiloes/sc-php

SocketCluster - PHP library for interacting with the SocketCluster.io

  Sources   Download

MIT

The Requires

 

The Development Requires

by Renato Moura

laravel php realtime broadcasting socketcluster

27/07 2016

v1.0.2

1.0.2.0 https://github.com/soleon-leiloes/sc-php

SocketCluster - PHP library for interacting with the SocketCluster.io

  Sources   Download

MIT

The Requires

 

The Development Requires

by Renato Moura

laravel php realtime broadcasting socketcluster

08/07 2016

v1.0.1

1.0.1.0 https://github.com/soleon-leiloes/sc-php

SocketCluster - PHP library for interacting with the SocketCluster.io

  Sources   Download

MIT

The Requires

 

The Development Requires

by Renato Moura

laravel php realtime broadcasting socketcluster

08/07 2016

v1.0.0

1.0.0.0 https://github.com/soleon-leiloes/sc-php

SocketCluster - PHP library for interacting with the SocketCluster.io

  Sources   Download

MIT

The Requires

 

The Development Requires

by Renato Moura

laravel php realtime broadcasting socketcluster