【发布时间】:2017-11-24 16:56:18
【问题描述】:
我正在开发一个配套的 React Native 应用程序来配合我的 RoR web 应用程序,并希望使用 ActionCable (websockets) 构建一个聊天功能。我无法让我的 React Native 应用程序与 ActionCable 通信。
我尝试了许多库,包括react-native-actioncable,但都没有运气。最初的连接似乎正在工作(我知道这一点是因为我之前遇到过错误,当我通过正确的参数时它们已经消失了)。
这是我的 React Native 代码的缩写版本:
import ActionCable from 'react-native-actioncable'
class Secured extends Component {
componentWillMount () {
var url = 'https://x.herokuapp.com/cable/?authToken=' + this.props.token + '&client=' + this.props.client + '&uid=' + this.props.uid + '&expiry=' + this.props.expiry
const cable = ActionCable.createConsumer(url)
cable.subscriptions.create('inbox_channel_1', {
received: function (data) {
console.log(data)
}
})
}
render () {
return (
<View style={styles.container}>
<TabBarNavigation/>
</View>
)
}
}
const mapStateToProps = (state) => {
return {
email: state.auth.email,
org_id: state.auth.org_id,
token: state.auth.token,
client: state.auth.client,
uid: state.auth.uid,
expiry: state.auth.expiry
}
}
export default connect(mapStateToProps, { })(Secured)
任何有更多将 ActionCable 连接到 React Native 经验的人可以帮助我吗?
【问题讨论】:
标签: react-native websocket actioncable