Coder Social home page Coder Social logo

php-api-clients / pusher Goto Github PK

View Code? Open in Web Editor NEW
36.0 8.0 11.0 429 KB

:ocean: Async first Pusher Client

License: MIT License

Makefile 0.93% PHP 99.07%
php reactphp php7 pusher async async-php websocket api-client pusher-client php-api-clients

pusher's Introduction

Pusher API Client for PHP 7 and 8

Linux Build Status Latest Stable Version Total Downloads Code Coverage License PHP 7 ready

Installation

To install via Composer, use the command below, it will automatically detect the latest version and bind it with ^.

composer require api-clients/pusher

Usage

$loop = Factory::create();
$client = AsyncClient::create($loop, 'Application ID here');
// OR when you need to specify the cluster
$client = AsyncClient::create($loop, 'Application ID here', null, 'cluster-here');

$client->channel('channel_name')->subscribe(
    function (Event $event) { // Gets called for each incoming event
        echo 'Channel: ', $event->getChannel(), PHP_EOL;
        echo 'Event: ', $event->getEvent(), PHP_EOL;
        echo 'Data: ', json_encode($event->getData()), PHP_EOL;
    },
    function ($e) { // Gets called on errors
        echo (string)$e;
    },
    function () { // Gets called when the end of the stream is reached
        echo 'Done!', PHP_EOL;
    }
);

$loop->run();

For more examples see the examples directory.

Features

This project aims to be 100% compatible with Pusher's features in v1.3.

  • Subscribe to channels
  • Presence channels
  • Authentication

License

The MIT License (MIT)

Copyright (c) 2017 Cees-Jan Kiewiet

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pusher's People

Contributors

carusogabriel avatar darkflib avatar davidwdan avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar robsonvn avatar wyrihaximus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pusher's Issues

php 8

Will there be an update for php 8?

How do I specify 'eu' cluster?

Hi,

I'm constantly getting this error:

ApiClients\Client\Pusher\PusherErrorException: Did you forget to specify the cluster when creating the Pusher instance? App key 8201*****02830 does not exist in this cluster.

I'm on the eu cluster

[Discussion] Reconnect if the websocket server closes the connection

If the websocket server closes the connect without an error the channel observable will complete. Currently, the user has to handle the reconnect themselves:

$client->channel('channel_name')
    ->repeatWhen(function (Observable $attempts) {
        return $attempts->delay(1000);
    })
    ->subscribe();

I think that a better solution is to have the channel observable handle the reconnect, by using a repeatWhen with a backoff timer. Something like repeatDelay from https://github.com/RxPHP/RxOperatorExtras

Handle connection closure

Copied from WyriHaximus/php-pusher-client#4 created by @davidwdan


Connection closure

Clients may close the WebSocket connection at any time.

The Pusher server may choose to close the WebSocket connection, in which case a close code and reason will be sent.

Clients SHOULD support the following 3 ranges

4000-4099: The connection SHOULD NOT be re-established unchanged.

4100-4199: The connection SHOULD be re-established after backing off. The back-off time SHOULD be at least 1 second in duration and MAY be exponential in nature on consecutive failures.

4200-4299: The connection SHOULD be re-established immediately.

https://pusher.com/docs/pusher_protocol

This can be implemented by converting the error messages into error observables and then using retryWhen to set the back-off time.

I'll work on this when I get a chance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.