我正在建立一个基本的应用程序,我想在那里得到的事件数据实时从拉维尔回声。我正在使用stack.io。一切都很好的工作与拉维尔redis和一切运行和工作没有问题。但是,我没有从react native获取事件的控制台日志,并且没有警告或错误。这是我的密码
React Nativeapp.js
import React from 'react';
import {
StyleSheet,
Text,
} from 'react-native';
import Echo from 'laravel-echo';
import socketio from 'socket.io-client';
const echo = new Echo({
host: 'projectb.io:6001', //tried 127.0.0.1, localhost, ws:// etc...
broadcaster: 'socket.io',
client: socketio,
});
echo
.channel('home')
.listen('NewMessage', ev => console.log(ev));
const App: () => React$Node = () => {
return (
<>
<Text>The usual stuff</Text>
</>
);
};
const styles = StyleSheet.create({
});
export default App;
laravle根,laravel-echo-server.json:
{
"authHost": "http://localhost",
"authEndpoint": "/broadcasting/auth",
"clients": [],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "http",
"socketio": {},
"secureOptions": 67108864,
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"subscribers": {
"http": true,
"redis": true
},
"apiOriginAllow": {
"allowCors": false,
"allowOrigin": "",
"allowMethods": "",
"allowHeaders": ""
}
}
新消息事件:
class NewMessage implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($message)
{
$this->message = $message;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('home');
}
}
.环境:
BROADCAST_DRIVER=redis
QUEUE_CONNECTION=redis
我用拉维尔廷克简单地做了一个 event(new App\Event\NewMessage("Hello Stack Overflow"))
. 它确实会立即显示在我的队列和laravelecho服务器上,但是在我的react原生服务器上,我没有得到任何控制台日志。
我正在使用 'RedisManager' => Illuminate\Support\Facades\Redis::class,
而不是 'Redis' => Illuminate\Support\Facades\Redis::class,
因为有一个错误指出redis ext找不到。现在呢 REDIS_CLIENT
设置为 predis
.
1条答案
按热度按时间af7jpaap1#
断然的。当我把主机ip作为服务器ip地址时,它工作正常。希望这对别人有帮助