Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Easily implement broadcasting in a React/Vue Typescript app (Starter Kits) #55170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
May 13, 2025

Conversation

tnylea
Copy link
Contributor

@tnylea tnylea commented Mar 25, 2025

This PR is going to make the process of implementing broadcasting in the React/Vue starter kits super simple.

This PR will detect if a users application utilizes react or vue. It will also check for the existense of the typescript dependency. Then, when the developer runs the php artisan install:broadcasting command it will install the necessary Echo hook or composable.

React

Running php artisan install:broadcasting, the use-echo-ts.stub will be installed in the resources/js/hooks folder. It can then be leveraged inside of any component, like so:

import { useEcho } from '@/hooks/use-echo';

useEcho('test-channel', 'test.event', (payload) => console.log(payload), [], 'public');

This will subscribe to test-channel and log the payload when test.event is fired.

Vue

Running php artisan install:broadcasting, the useEcho-ts.stub will be installed in the resources/js/composables folder. It can then be leveraged inside of any component, like so:

import { useEcho } from '@/composables/useEcho';

useEcho('test-channel', 'test.event', (payload) => { console.log(payload) }, [], 'public');

This is the exact same as React except the useEcho is stored in the composables folder as opposed to the hooks folder.

Configuration

Before using this hook/composable, echo needs to be configured, like so:

app.tsx

import { configureEcho } from './hooks/use-echo';

configureEcho({
    broadcaster: 'reverb',
    key: import.meta.env.VITE_REVERB_APP_KEY,
    wsHost: import.meta.env.VITE_REVERB_HOST,
    wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,
    wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
    forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https',
    enabledTransports: ['ws', 'wss'],
});

This will allow developers to modify echo to use reverb, pusher, ably or any other websocket service. This is going to be added by default (Still adding this functionality to the install:broadcasting command. After I finish implementing the publishing of the configure, this update will be good to go!

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@tnylea tnylea marked this pull request as ready for review March 26, 2025 13:33
@taylorotwell taylorotwell marked this pull request as draft March 27, 2025 17:15
@tnylea tnylea marked this pull request as ready for review March 28, 2025 20:10
@taylorotwell taylorotwell marked this pull request as draft March 29, 2025 16:56
@taylorotwell
Copy link
Member

Drafting this while I review.

@tnylea
Copy link
Contributor Author

tnylea commented Apr 4, 2025

I've updated this PR to only include the configureEcho functionality when installing in a React/Vue(typescript) app.

The actual javascript functionality and hooks have been moved over to this PR. The updated version of Echo should be published before merging this.

@taylorotwell taylorotwell marked this pull request as ready for review May 9, 2025 17:01
/**
* Write an array of key-value pairs to the environment file.
*
* @param array $variables
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param array $variables
* @param array<string, mixed> $variables

@taylorotwell taylorotwell merged commit e134fe9 into laravel:12.x May 13, 2025
58 of 59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.