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.
Download georgeboot/laravel-echo-api-gateway
More information about georgeboot/laravel-echo-api-gateway
Files in georgeboot/laravel-echo-api-gateway
Package laravel-echo-api-gateway
Short Description Use Laravel Echo with API Gateway Websockets
License MIT
Homepage https://github.com/georgeboot/laravel-echo-api-gateway
Informations about the package laravel-echo-api-gateway
laravel-echo-api-gateway
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.
As soon as version 1.0 will be released, this package will be suitable for production workloads. Until then, it is advised to only use this package for non-critical / non-production projects.
Requirements
In order to use this package, your project needs to meet the following criteria:
- PHP 7.4 or 8.x
- Laravel 6 to 11
- Uses either bref or Laravel Vapor to deploy to AWS
- Has a working queue
- Uses Laravel Mix or any other tool to bundle your assets
Installation
Installation of this package is fairly simply.
First we have to install both the composer and npm package:
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:
- Name:
lookup-by-connection
, key:connectionId
, no sort key, projected: ALL - 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
:
Generate front-end code
Add to your javascript file:
You can also enable console output by passing a debug: true
otpion to your window.Echo intializer :
Lastly, you have to generate your assets by running Laravel Mix. After this step, you should be up and running.
All versions of laravel-echo-api-gateway with dependencies
ext-json Version *
aws/aws-sdk-php Version ^3.308
bref/bref Version ^1.1|^2.0
guzzlehttp/guzzle Version ^6.3|^7.0
laravel/framework Version ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0