反应本机自定义主机推送器连接
React native custom host pusher connection
似乎无法连接到推送器。我已经在这些设备上工作了好几天,但似乎无法连接到推送器。版本 6.0.3
import Pusher from 'pusher-js/react-native';
componentDidMount() {
this.willFocusSubscription = this.props.navigation.addListener(
'willFocus',
() => {
try {
this.pusher = new Pusher('key', {
wsHost: 'host',
wsPort: 6001,
enabledTransports: ['ws'],
disableStats:true,
});
Pusher.log = (msg) => {
console.log('Pusher message ' + msg);
};
} catch (error) {
console.log('error', error)
}
this.group_channel = this.pusher.subscribe('groupchat.' + session_id);
this.pusher.connection.bind('GroupMessageSent', (data) => {
console.log('connected', data)
});
this.group_channel.bind('GroupMessageSent', (data) => {
console.log('data', data)
});
})
}
推送消息推送器: : ["Connecting",{"transport":"xhr_polling","url":"https://sockjs-4444.pusher.com:443/pusher/app/DOCKOTO_KEY?protocol=7&client=js&version=6.0.3"}]
https://snack.expo.io/@jsfit/pusher
我已经检查过推送器在本地主机上对我来说工作正常
我认为主要原因是你的 ws ws://test.dockoto.com:6001
Laravel 如您所知,WebSockets 默认端口 6001
但您仍然需要在服务器上打开该端口。
共享主机我认为如果需要的话你必须联系你的主机提供商打开端口
EC2:
import Pusher from 'pusher-js/react-native';
componentDidMount() {
this.willFocusSubscription = this.props.navigation.addListener(
'willFocus',
() => {
try {
this.pusher = new Pusher('key', {
wsHost: 'host',
wsPort: 6001,
enabledTransports: ['ws'],
disableStats:true,
});
Pusher.log = (msg) => {
console.log('Pusher message ' + msg);
};
} catch (error) {
console.log('error', error)
}
this.group_channel = this.pusher.subscribe('groupchat.' + session_id);
this.pusher.connection.bind('GroupMessageSent', (data) => {
console.log('connected', data)
});
this.group_channel.bind('GroupMessageSent', (data) => {
console.log('data', data)
});
})
}
推送消息推送器: : ["Connecting",{"transport":"xhr_polling","url":"https://sockjs-4444.pusher.com:443/pusher/app/DOCKOTO_KEY?protocol=7&client=js&version=6.0.3"}]
https://snack.expo.io/@jsfit/pusher
我已经检查过推送器在本地主机上对我来说工作正常
我认为主要原因是你的 ws ws://test.dockoto.com:6001
Laravel 如您所知,WebSockets 默认端口 6001
但您仍然需要在服务器上打开该端口。
共享主机我认为如果需要的话你必须联系你的主机提供商打开端口
EC2: