Download the PHP package georgeboot/laravel-echo-api-gateway without Composer

On this page you can find all versions of the php package georgeboot/laravel-echo-api-gateway. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-echo-api-gateway

laravel-echo-api-gateway

CI codecov

This package enables you to use API Gateway‘s Websockets as a driver for Laravel Echo , so you don’t have to use services like Pusher or Socket.io.

It works by setting up a websocket API in API Gateway, and configure it to invoke a Lambda function, every time a message is sent to the websocket. This package includes and autoconfigures a handler to respond to these websocket messages. We also configure Laravel to use this connection as a broadcast driver.

This package currently only works with either Bref or Laravel Vapor, though the latter one involves some manual set-up.

Requirements

In order to use this package, your project needs to meet the following criteria:

Installation

Installation of this package is fairly simply.

First we have to install both the composer and npm package:

laravel-echo is a peer dependency: the package works with the version your app already uses (v1.10+ or v2).

Platform-specific instructions

A. When using Bref

Next, when using Bref, we have to add some elements to our serverless.yml file. If using Vapor, these resources have to be created by hand using the AWS CLI or console.

Add a new function that will handle websocket events (messages etc):

Add a resource to create and configure our DynamoDB table, where connections will be stored in:

Add the following iamRoleStatement to enable our Lambda function to access the table:

Add an environment variable to autogenerate our websocket URL:

Next, create the PHP handler file in handlers/websocket.php

Now, deploy your app by running serverless deploy or similar. Write down the websocket url the output gives you.

B. When using Vapor

When using Vapor, you will have to create these required resources by hand using the AWS CLI or Console:

B1. DynamoDB table for connections

Create a DynamoDB table for the connections. Use connectionId (string) as a HASH key, and channel (string) as a SORT key. Set the capacity setting to whatever you like (probably on-demand).

Create 2 indexes:

  1. Name: lookup-by-connection, key: connectionId, no sort key, projected: ALL
  2. Name: lookup-by-channel, key: channel, no sort key, projected: ALL
B2. API Gateway

Create a new Websocket API. Enter a name and leave the route selection expression to what it is. Add a $disconnect and $default. Set both integrations to Lambda and select your CLI lambda from the list. Set the name of the stage to what you desire and create the API. Once created, write down the ID, as we'll need it later.

B3. IAM Permissions

In IAM, go to roles and open laravel-vapor-role. Open the inline policy and edit it. On the JSON tab, add "execute-api:*" to the list of actions.

Then, login to Laravel Vapor, go to team settings, AWS Accounts, click on Role next to the correct account and deselect Receive Updates.

Edit your .env:

Signing secret

Private and presence channels are authorized by your app (/broadcasting/auth), which signs the socket id and channel name. The websocket handler verifies that signature before subscribing the connection. By default both use your APP_KEY. If the websocket handler runs as a separate app, set the same LARAVEL_ECHO_API_GATEWAY_SECRET on both instead of sharing your APP_KEY.

Generate front-end code

Add to your javascript file:

The broadcaster export from previous versions keeps working: new Echo({ broadcaster, ... }).

With TypeScript and laravel-echo v2, its typings do not accept custom connector classes yet, so cast the option: broadcaster: Connector as any.

Using @laravel/echo-react or @laravel/echo-vue

Using it outside the browser (Node.js, Electron)

The connector only needs the global WebSocket and fetch, available in Node.js 22+ (or 18+ with a WebSocket polyfill such as ws assigned to globalThis.WebSocket).

To authorize private channels with your own logic, pass a custom handler. It receives the socket id and channel name and must call back with the response of your /broadcasting/auth endpoint:

You can also pass channelAuthorization: { endpoint, headers } to only change the endpoint or add headers. Authorization failures and rejected subscriptions are reported to channel.error(callback).

Options

Option Default Description
host The websocket URL of your API Gateway stage.
authEndpoint /broadcasting/auth Endpoint used to authorize private and presence channels.
bearerToken Sent as Authorization: Bearer ... to the auth endpoint.
auth.headers {} Extra headers sent to the auth endpoint.
channelAuthorization { endpoint, headers, customHandler }, see above.
pingInterval 60000 Milliseconds between keep-alive pings. API Gateway closes idle connections after 10 minutes.
reconnectDelay 1000 Milliseconds before the first reconnect attempt. Later attempts back off exponentially.
maxReconnectDelay 30000 Upper bound for the reconnect delay.
debug false Log connection activity to the console.

API Gateway closes every websocket connection after 2 hours. The connector reconnects automatically and subscribes again to every channel you joined, so your listeners keep receiving events.

You can also enable console output by passing a debug: true option to your Echo initializer:

Lastly, build your assets (for example with Vite or Laravel Mix). After this step, you should be up and running.

Limitations


All versions of laravel-echo-api-gateway with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0|^8.1|^8.2|^8.3|^8.4|^8.5
ext-json Version *
aws/aws-sdk-php Version ^3.308
bref/bref Version ^1.1|^2.0|^3.0
guzzlehttp/guzzle Version ^6.3|^7.0
laravel/framework Version ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package georgeboot/laravel-echo-api-gateway contains the following files

Loading the files please wait ...