【发布时间】:2021-08-04 23:39:36
【问题描述】:
我需要在我们的 Rail 项目中实现 WebSocket 同步。 MetaApi 项目使用 Socket.Io 作为默认支持。只找到了 2 个项目 (websocket-client-simple) 并且使用原生 socket.io 已过时。我们尝试使用Faye-Websocket 和socketcluster-client-ruby 来实现这一点,但没有成功。
import ioClient from 'socket.io-client';
const socket = ioClient('https://mt-client-api-v1.agiliumtrade.agiliumtrade.ai', {
path: '/ws',
reconnection: false,
query: {
'auth-token': 'token'
}
});
const request = {
accountId: '865d3a4d-3803-486d-bdf3-a85679d9fad2',
type: 'subscribe',
requestId: '57bfbc9f-108d-4131-a300-5f7d9e69c11b'
};
socket.on('connect', () => {
socket.emit('request', request);
});
socket.on('synchronization', data => {
console.log(data);
if (data.type === 'authenticated') {
console.log('authenticated event received, you can send synchronize now');
}
});
socket.on('processingError', err => {
console.error(err);
});
【问题讨论】:
-
您介意添加一些有关您看到的错误的详细信息吗?
-
@Breno Perucchi 为什么你不能使用 Actioncable 或 cableready?
标签: ruby-on-rails websocket socket.io faye