laravel 与“ws://ws.pusherapp.com/app/...”的 WebSocket 连接失败:在建立连接之前 WebSocket 已关闭
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36066322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WebSocket connection to 'ws://ws.pusherapp.com/app/...' failed: WebSocket is closed before the connection is established
提问by Rayzor286
I have a problem with a package made for the Framework Laravel. I would like to make a chat on my project to make people talk to each other.
我有一个为框架 Laravel 制作的包的问题。我想就我的项目进行聊天,让人们相互交谈。
The problem is when I try to access to my app on pusher, I receive these 2 error codes :
问题是当我尝试在 pusher 上访问我的应用程序时,我收到以下 2 个错误代码:
WebSocket connection to 'ws://ws.pusherapp.com/app/my_app_key?protocol=7&client=js&version=2.2.4&flash=false' failed: WebSocket is closed before the connection is established.
pusher.js:12 Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":4001,"message":"Could not find app by key my_app_key. Perhaps you're connecting to the wrong cluster."}}}
This package is called Confer (https://github.com/dazzz1er/confer).
这个包叫做 Confer ( https://github.com/dazzz1er/confer)。
All my files are correct but it doesn't work ! I'm on laravel 5.1
我所有的文件都是正确的,但它不起作用!我在 Laravel 5.1
in config/services.php
在 config/services.php
'pusher' => [
'public' => 'my_app_key',
'secret' => 'my_secret_key',
'app_id' => 'my_app_id'
]
my blade template
我的刀片模板
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> My project - @yield('title') </title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="./css/style.css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" type="text/css" href="../css/sweetalert.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link href="/vendor/confer/css/confer.css" rel="stylesheet">
<script src="./js/jquery-1.12.0.min.js" charset="utf-8"></script>
<script src="./js/bootstrap.min.js" charset="utf-8"></script>
<script src="./js/jcarousel.js"></script>
<script src="./js/jcarousel-basic.js" charset="utf-8"></script>
<script src="../../js/sweetalert.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body class="homepage">
@include('confer::confer')
@include('sweet::alert')
@include('layouts.includes.nav')
@include('layouts.includes.header')
@yield('content')
@include('layouts.includes.footer')
<script src="./js/pusher.js"></script>
<script src="./js/moment.js"></script>
@include('confer::js')
</body>
</html>
Thank you for your help ! :)
感谢您的帮助 !:)
EDIT : I receive a response, it's a difference between versions ! Can anyone give me help to convert Confer in Laravel 5 to Laravel 5.1 ? Thank you ! :)
编辑:我收到回复,这是版本之间的差异!谁能帮我将 Laravel 5 中的 Confer 转换为 Laravel 5.1?谢谢 !:)
Here is the complete demo in laravel 5 ! https://github.com/dazzz1er/confer-demo
这是 laravel 5 中的完整演示! https://github.com/dazzz1er/confer-demo
回答by marybane
If you're not from the US i think you need to change the cluster to "eu" https://pusher.com/docs/clusters#/lang=php
如果您不是来自美国,我认为您需要将集群更改为“eu” https://pusher.com/docs/clusters#/lang=php
回答by Luis L
I don't pretend to copy the answers of others but I just wanted to share what worked for me. In the env file I hadn't configured BROADCAST_DRIVER=pusherproperly. Then I checked the clusterto be the same one as the one that was given to me when I created the pusher app in their website. You can also find the cluster name you were assigned to under the "App Keys" tab. Then I restarted Chrome Web Browserand finally I restarted the serverby running valet restart. You might restart your server with a different command depending on your development enviroment.
我不会假装复制别人的答案,但我只是想分享对我有用的东西。在 env 文件中,我没有正确配置BROADCAST_DRIVER=pusher。然后我检查了集群与我在他们的网站上创建 pusher 应用程序时给我的集群相同。您还可以在“应用程序密钥”选项卡下找到分配给您的集群名称。然后我重新启动了 Chrome Web 浏览器,最后通过运行 valet restart 重新启动了服务器。根据您的开发环境,您可以使用不同的命令重新启动服务器。
回答by Hyman Franklin
The error message here Could not find app by key my_app_key
suggests that you haven't replaced those with your actual Pusher credentials, which you can find on your Pusher dashboard.
此处的错误消息Could not find app by key my_app_key
表明您尚未使用实际的 Pusher 凭据替换这些凭据,您可以在 Pusher 仪表板上找到这些凭据。
That error is thrown by the Pusher library when it isn't given valid credentials. If you've updated config/services.php
correctly you may need to restart your server for the changes to take effect.
当 Pusher 库没有提供有效凭据时,它会抛出该错误。如果您已config/services.php
正确更新,则可能需要重新启动服务器以使更改生效。
You need to change your config/services.php
to use keys that you can find from the Pusher dashboard under the "App keys" section. For example:
您需要将您的config/services.php
密钥更改为使用可以从“应用程序密钥”部分下的 Pusher 仪表板中找到的密钥。例如: