可以的,我刚刚测试了一下你描述的嵌套对象。
it('test change room properties', () =>
new Promise(async resolve => {
const roomName = 'tcp0_r';
const p0 = newPlay('tcp0_0');
const p1 = newPlay('tcp0_1');
let f0 = false;
let f1 = false;
await p0.connect();
await p0.createRoom({ roomName });
p0.on(Event.ROOM_CUSTOM_PROPERTIES_CHANGED, async () => {
const props = p0.room.customProperties;
expect(props.title).to.be.equal('room311');
expect(props.gold).to.be.equal(1000);
expect(props.data.num).to.be.equal(123);
expect(props.data.detail).to.be.equal('hello');
f0 = true;
if (f0 && f1) {
await p0.close();
await p1.close();
resolve();
}
});
await p1.connect();
await p1.joinRoom(roomName);
p1.on(Event.ROOM_CUSTOM_PROPERTIES_CHANGED, async () => {
const props = p1.room.customProperties;
expect(props.title).to.be.equal('room311');
expect(props.gold).to.be.equal(1000);
expect(props.data.num).to.be.equal(123);
expect(props.data.detail).to.be.equal('hello');
f1 = true;
if (f0 && f1) {
await p0.close();
await p1.close();
resolve();
}
});
const props = {
title: 'room311',
gold: 1000,
data: {
num: 123,
detail: 'hello',
},
};
await p1.room.setCustomProperties(props);
debug(`current room title: ${props.title}`);
expect(props.title).to.be.equal('room311');
debug(`current room gold: ${props.gold}`);
expect(props.gold).to.be.equal(1000);
debug(`current room num: ${props.data.num}`);
expect(props.data.num).to.be.equal(123);
debug(`current room detail: ${props.data.detail}`);
expect(props.data.detail).to.be.equal('hello');
}));
后面也有 Player CustomProperties 的单元测试,就是嵌套的。
Room Properties 和 Player Properties 数据结构是一样的。