我曾尝试使用发布此包
php artisan vendor:publish --provider="BeyondCode\LaravelWebSockets\WebSocketsServiceProvider" --tag="migrations"
Run Code Online (Sandbox Code Playgroud)
但我得到
Unable to locate publishable resources
publishing complete
Run Code Online (Sandbox Code Playgroud)
我不知道问题的原因是什么。任何可以帮助我的人。
安装输出
Installing beyondcode/laravel-websockets (1.4.0): Downloading (100%)
symfony/polyfill-intl-idn suggests installing ext-intl (For best performance)
symfony/psr-http-message-bridge suggests installing nyholm/psr7 (For a super lightweight PSR-7/17 implementation)
paragonie/random_compat suggests installing ext-libsodium (Provides a modern crypto API that can be used to generate random bytes.)
symfony/event-dispatcher suggests installing symfony/dependency-injection
symfony/var-dumper suggests installing ext-intl (To show region name in time zone dump)
symfony/http-kernel suggests installing symfony/browser-kit
symfony/http-kernel suggests installing symfony/config
symfony/http-kernel …Run Code Online (Sandbox Code Playgroud) 我设置了一个事件和新频道:
class TaskCreated implements shouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $task;
public function __construct(Task $task)
{
$this->task = $task;
}
}
Run Code Online (Sandbox Code Playgroud)
并安装 Echo 并进行设置
import Echo from "laravel-echo"
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'pusher-key',
cluster: 'ap2',
encrypted: true
});
Run Code Online (Sandbox Code Playgroud)
然后我在发布任务时调用 TaskCreated 事件
event(new TaskCreated($task));
Run Code Online (Sandbox Code Playgroud)
然而,问题是 Echo 不听推送日志或任何东西。即使在 laravel-websockets 中,事件是作为 api 消息创建的。
这是 vue js Echo 实现:
mounted () {
axios.get('/tasks').then(response => (this.tasks = response.data));
Echo.channel('taskCreated').listen('TaskCreated', (e) => {
console.log(e);
this.tasks.push(task.body)
});
Run Code Online (Sandbox Code Playgroud)
在仪表板中:
api-message Channel: …
WebSocket 允许双向通信:服务器可以向浏览器发送消息,浏览器 - 客户端 - 可以通过相同的连接进行响应。
我正在 Laravel 6 中使用以下方法实现聊天应用程序:
我已经知道服务器触发事件并且客户端侦听这些事件如下。
composer require beyondcode/laravel-websockets
config/broadcasting.php. 'pusher' => [
'driver' => 'pusher',
'key' => xxx,
'secret' => xxx,
'app_id' => xxx,
'options' => [
'cluster' => xxx,
'encrypted' => true,
'useTLS' => true,
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'https',
],
],
]
Run Code Online (Sandbox Code Playgroud)
config/websockets.php'apps' => [
[
'id' => xxx,
'name' …Run Code Online (Sandbox Code Playgroud) 我正在使用 Pusher Laravel Webaockets 包的替换。
\n\n在我的应用程序中 Laravel Echo 尝试连接 v\xc3\xada wss 而不是 ws,因此失败。
\n\n我的资源/js/bootstrap.js:
\n\nimport Echo from \'laravel-echo\'\nwindow.Pusher = require(\'pusher-js\');\n\nwindow.Echo = new Echo({\n broadcaster: \'pusher\',\n key: process.env.MIX_PUSHER_APP_KEY,\n cluster: process.env.MIX_PUSHER_APP_CLUSTER,\n wsHost: window.location.hostname,\n wsPort: 6001,\n disableStats: true,\n encrypted: false,\n enabledTransports: [\'ws\'],\n});\nRun Code Online (Sandbox Code Playgroud)\n\nconfig/broadcasting.php 中的广播连接:
\n\n\'pusher\' => [\n \'driver\' => \'pusher\',\n \'key\' => env(\'PUSHER_APP_KEY\'),\n \'secret\' => env(\'PUSHER_APP_SECRET\'),\n \'app_id\' => env(\'PUSHER_APP_ID\'),\n \'options\' => [\n \'cluster\' => env(\'PUSHER_APP_CLUSTER\'),\n \'encrypted\' => false,\n \'host\' => \'127.0.0.1\',\n \'port\' => 6001,\n \'scheme\' => \'http\',\n ],\n …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个聊天应用程序,并使用Beyondcode/laravel-websockets来实现。当我在本地使用它时,它工作得很好,但在服务器上无法使其运行。
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
encrypted: false,
wsHost: window.location.hostname,
wsPort: 6001,
});
Run Code Online (Sandbox Code Playgroud)
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' => false,
'host' => env('WEBSOCKET_HOST'),
'port' => env('WEBSOCKET_PORT'),
'scheme' => env('WEBSSOCKET_SCHEME'),
],
],
Run Code Online (Sandbox Code Playgroud)
'dashboard' => [
'port' => env('LARAVEL_WEBSOCKETS_PORT', 6001),
],
'apps' => [
[
'id' => env('PUSHER_APP_ID'),
'name' …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用服务器上 nginx 上的 ssl 让 laravel-websockets 在我的网站上工作。我一直在使用 Laravel 和 echo。它在我的本地计算机上完美运行。
这是我在控制台中遇到的错误
WebSocket connection to 'wss://www.site.com:6001/app/passcode?protocol=7&client=js&version=4.3.1&flash=false' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
Run Code Online (Sandbox Code Playgroud)
这是我的文件
配置/广播.php
/*
|--------------------------------------------------------------------------
| Default Broadcaster
|--------------------------------------------------------------------------
|
| This option controls the default broadcaster that will be used by the
| framework when an event needs to be broadcast. You may set this to
| any of the connections defined in the "connections" array below.
|
| Supported: "pusher", "redis", "log", "null"
|
*/
'default' => env('BROADCAST_DRIVER', …Run Code Online (Sandbox Code Playgroud) 我在Laravel 后端使用Beyondco Larevel Websockets,在 Flutter 前端使用pusher_client和laravel_echo。
我一直在尝试从我的 ios 模拟器连接到我的 Laravel 后端主机,它使用了代客安全,但失败了。
我的颤振连接:
PusherClient getPusherClient(String token) {
PusherOptions options = PusherOptions(
host: 'my-local-server.test',
wsPort: 6001,
wssPort: 6001,
cluster: DotEnv.env['PUSHER_APP_CLUSTER'],
encrypted: true,
auth: PusherAuth('https://my-local-server.test/api/broadcasting/auth',
headers: {'Authorization': 'Bearer $token'})
);
return PusherClient(DotEnv.env['PUSHER_APP_KEY'], options,
enableLogging: true, autoConnect: false);
}
pusherClient = getPusherClient(token);
pusherClient.connect();
pusherClient.onConnectionStateChange((state) {
print(
"previousState: ${state.previousState}, currentState: ${state.currentState}");
});
pusherClient.onConnectionError((error) {
print(error.message);
});
Run Code Online (Sandbox Code Playgroud)
从https://my-local-server.test/laravel-websockets我从来没有看到来自 Flutter 的请求,但是如果我从我的 Laravel 后端触发一个事件,它会被记录下来。
请帮助我解决设置中的问题,为什么我无法从 Flutter 应用程序连接到运行 laravel-websocket 的 SSL …
实现一个简单的GraphQl查询(例如 simple)Mutation后Subscription,当我尝试将其运行subscription到graphql-playground:
subscription {
userCreated{
name
username
password
}
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
{
"error": "Could not connect to websocket endpoint ws://127.0.0.1:8000/graphql.
Please check if the endpoint url is correct."
}
Run Code Online (Sandbox Code Playgroud)
GraphQl 架构:
#...
type User {
id: Int!
name: String
email: String
product : [Product!]
}
type Mutation {
createUser(
name: String!
password: String!
email : String!
): User @field(resolver:"UserMutator@create") @broadcast(subscription: "userCreated")
}
type Subscription {
userCreated: User
}
Run Code Online (Sandbox Code Playgroud)
UserMutator班级: …
我正在尝试在 larvel-9.0 项目上设置 websockets。当我尝试打开 /laravel-websockets 时,我在控制台中收到以下错误。项目在 Ubuntu 20.04.4 上安装。
Pusher.min.js:8 与 'wss://dev.mydomain.in:6001/app/mywebsocketkey?protocol=7&client=js&version=4.3.1&flash=false' 的 WebSocket 连接失败:
当我尝试通过带有 url 的邮递员连接它时,我收到成功响应
wss://dev.mydomain.in:6001/app/mywebsocketkey?protocol=7&client=js&version=4.3.1&flash=false
我在邮递员中收到以下回复。
{
"event": "pusher:connection_established",
"data": "{\"socket_id\":\"371175048.259495464\",\"activity_timeout\":30}"
}
Run Code Online (Sandbox Code Playgroud)
我遵循了Websockets 文档。
这是broadcast.php配置
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'useTLS' => true,
'encrypted' => true,
'host' => 'dev.mydomain.in',
'port' => 6001,
'scheme' => 'https',
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
]
], …Run Code Online (Sandbox Code Playgroud) 我正在使用 laravel soketi 包。我不想使用 laravel-echo 进行客户端连接。所以,我正在用 firecamp 进行测试。但无法连接。
Soketi 已启动并运行
Server is up and running!
The Websockets server is available at 127.0.0.1:6001
The HTTP API server is available at http://127.0.0.1:6001
The /usage endpoint is available on port 9601.
Run Code Online (Sandbox Code Playgroud)
在 firecamp 中连接时我使用 url asws://localhost:6001/
但无法连接。

那么,如何连接呢?
laravel ×9
php ×3
websocket ×3
laravel-echo ×2
flutter ×1
graphql ×1
javascript ×1
laravel-7 ×1
nginx ×1
node.js ×1
server ×1
uwebsockets ×1
vue.js ×1