Giter Club home page Giter Club logo

octamp-client's Introduction

Octamp Client

Packagist PHP Version License Test codecov

Octamp Client is an open source client for WAMP (Web Application Messaging Protocol), for PHP.

Octamp Client uses Open Swoole, is a high-performance network framework based on an event-driven, asynchronous, non-blocking I/O coroutine programming model for PHP.

We also design the Octamp Client functions to be identical to AutobahnJS

The name Octamp is from Octopus + WAMP

Supported WAMP Features

  • Publish
  • Subscribe
  • Call
  • Call Progressive
  • Register

Requierements

  • PHP >= 8.1
  • Swoole / OpenSwoole Extension

Installation

composer require octamp/client

Example

<?php

use Octamp\Client\Auth\WampcraAuthenticator;
use Octamp\Client\Peer;
use Octamp\Client\Session;

require_once __DIR__ . '/../../vendor/autoload.php';

\Co\run(function () {
    $client = new Peer('crossbar', 9000);
    
    $client->onOpen(function (Session $session) {
        // subscribe
        $session->subscribe('hello', function (array $args) {
            echo 'Event ' . $args[0] . PHP_EOL;
        });
    
        // publish
        $session->publish('hello', ['hello octamp'], [], ['exclude_me' => false]);
    
        // publish with acknowledgement
        $session
            ->publish('hello', ['hello octamp with acknowledgement'], [], ['acknowledge' => true, 'exclude_me' => false])
            ->then(
                function () {
                    echo 'Publish Acknowledged!' . PHP_EOL;
                },
                function ($error) {
                    echo 'Publish Error ' . $error . PHP_EOL;
                },
            );
    
        // register
        $session->register('add', function (array $args) {
            return $args[0] + $args[1];
        });
    
        // call
        $session->call('add', [1, 3])->then(function ($result) {
            echo 'Result ' . $result . PHP_EOL;
        });
    });
    
    $client->open();
});

TODOs

  • Call Cancel
  • Call Timeout
  • Unsubscribe
  • RPC Progress Call
  • Auto Reconnect
  • Subprotocol Handling
  • Heartbeat
  • Custom Error Handling
  • TLS connection
  • Session Logging
  • Session Prefix
  • Pattern Base Subscription / Registration

octamp-client's People

Contributors

cydrickn avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

dheia

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.