const Int64BE = require("int64-buffer").Int64BE;
//注册
RTMClient.RTMRegistration.register();
//构造
let client = new RTMServerClient({
pid: 11000001,
secret: 'ef3617e5-e886-4a4e-9eef-7263c0320628',
host: 'rtm-test.ilivedata.com',
port: 13315,
reconnect: true,
timeout: 20 * 1000,
debug: true
});
//添加监听
client.on('connect', function() {
console.log('connected!');
//发送业务消息
let from = new Int64BE(0, 1234);
let to = new Int64BE(0, 5678);
client.sendMessage(from, to, 8, 'hello !', '', new Int64BE(0), 10 * 1000, function(err, data) {
if (err) {
console.error(err.message);
return;
}
if (data) {
console.log(data);
}
});
});
client.on('error', function(err) {
console.error(err.message);
});
client.on('close', function() {
console.log('closed!');
});
//添加推送监听
let pushName = RTMConfig.SERVER_PUSH.recvMessage;
client.processor.addPushService(pushName, function(data) {
console.log('[PUSH] ' + pushName + ': ', data);
});
// 开启连接
client.connect();
//destroy
//client.destroy();
//client = null;