0
我使用Ruby Socket.IO client simple並試圖用Ruby複製這個JS代碼,但沒有運氣。 JS代碼正常工作,但是,Ruby版本在'auth'發出時不會產生回調輸出'Authentication successful'。Ruby Socket.IO回調
儘管在Ruby中auth成功,因爲我可以在auth後發出其他私有方法。唯一的問題是,爲什麼回調不工作
JS
var ws = io('https://test.com')
ws.on('connect', function() {
auth(ws, pubKey, secKey, function (err, auth) {
if (err) return console.error('Error', err);
if (auth.success)
console.log('Authentication successful');
else
console.log('Authentication failed');
});
});
function auth(ws, pubKey, secKey, cb) {
var data = { apiKey: pubKey, cmd: 'getAuthInfo', nonce: Date.now() };
var sig = crypto.sign(data, secKey);
ws.emit('auth', data, sig, cb);
}
紅寶石
require 'socket.io-client-simple'
require 'date'
ws = SocketIO::Client::Simple.connect 'https://test.com'
socket.on :connect do
auth(ws, pubKey, secKey, method(:auth_callback))
end
def auth(ws, pubKey, secKey, cb)
data = { apiKey: pubKey, cmd: 'getAuthInfo', nonce: DateTime.now }
sig = Crypto.sign(data, secKey)
ws.emit :auth, [data.to_json, sig, cb]
end
def auth_callback(err, auth)
if auth.success
puts 'Authentication successful'
end
end
謝謝,我看到你的意思,但它看起來像,我實際上不能得到在ruby中發射方法的響應,就像在js中一樣。看起來像是socket.io-client-simple包裝的限制 –