聊天:增加私聊部分逻辑
测试:增加测试脚本,减少socket断开的打印
This commit is contained in:
@@ -139,7 +139,7 @@ class PinusWSClient {
|
||||
this.send(this._package.encode(Package.TYPE_HANDSHAKE, Protocol.strencode(JSON.stringify(this.handshakeBuffer))));
|
||||
}
|
||||
onClose(e) {
|
||||
console.error('[Pinus] connect close:', e);
|
||||
console.error('[Pinus] connect close');
|
||||
// this.emit(Pinus.EVENT_CLOSE,e);
|
||||
}
|
||||
onIOError(e) {
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { MSG_TYPE, ON_MSG_ROUTE } from './../app/consts';
|
||||
import { indexOf } from 'underscore';
|
||||
import { COM_TEAM_STATUS, DEFAULT_HEROES } from './../../shared/consts/consts';
|
||||
import { Client } from './Client';
|
||||
import { COM_BTL_QUALITY } from './../app/consts/constModules/itemConst';
|
||||
import 'mocha';
|
||||
import { PinusWSClient } from 'pinus-robot-plugin';
|
||||
import { expect } from 'chai';
|
||||
import { checkDisplayItems, checkSuccessResponse } from './CheckPatten';
|
||||
|
||||
const TEXT_MSG = {type: MSG_TYPE.TEXT, content: 'hello world'}
|
||||
|
||||
function sendPrivateMessageParm(targetRoleInfo, msg) {
|
||||
const { roleId: targetRoleId, roleName: targetRoleName } = targetRoleInfo;
|
||||
const result = {targetRoleId, targetRoleName, ...msg};
|
||||
return result;
|
||||
}
|
||||
|
||||
describe('私聊消息发送和接收', function() {
|
||||
let pinusClient: PinusWSClient;
|
||||
let pinusClientT: PinusWSClient; // 用做测试队友
|
||||
let roleInfo;
|
||||
let roleInfoT;
|
||||
|
||||
beforeEach(function(done) {
|
||||
const c = new Client();
|
||||
const cT = new Client('13121622738');
|
||||
const timer = setInterval(() => {
|
||||
if (c.client && cT.client) {
|
||||
pinusClient = c.client;
|
||||
roleInfo = c.roleInfo;
|
||||
pinusClientT = cT.client;
|
||||
roleInfoT = cT.roleInfo;
|
||||
clearInterval(timer);
|
||||
done();
|
||||
}
|
||||
}, 500);
|
||||
});
|
||||
|
||||
afterEach(function(done) {
|
||||
pinusClient.disconnect();
|
||||
pinusClientT.disconnect();
|
||||
done();
|
||||
});
|
||||
|
||||
it('两个玩家互相发送', function(done) {
|
||||
pinusClientT.on(ON_MSG_ROUTE, (msg) => {
|
||||
console.log(ON_MSG_ROUTE , msg);
|
||||
checkSuccessResponse(msg);
|
||||
expect(msg.data.content).to.equal(TEXT_MSG.content);
|
||||
});
|
||||
|
||||
pinusClient.request('chat.chatHandler.sendPrivateMessage', sendPrivateMessageParm(roleInfoT, TEXT_MSG), (res) => {
|
||||
checkSuccessResponse(res, false);
|
||||
setTimeout(() => {
|
||||
done();
|
||||
}, 200);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user