refactor: new protocols
This commit is contained in:
parent
9ed7026543
commit
ff7e41cf9d
|
@ -1,5 +1,5 @@
|
|||
// 2nd party.
|
||||
import {create as createClient} from '@avocado/client';
|
||||
import {create as createClient} from '@avocado/client/socket';
|
||||
import {EntityList} from '@avocado/entity';
|
||||
import {ActionRegistry} from '@avocado/input';
|
||||
import {Stage} from '@avocado/graphics';
|
||||
|
@ -216,8 +216,15 @@ const predictionHandle = setInterval(() => {
|
|||
|
||||
// State updates.
|
||||
function onMessage(message) {
|
||||
if ('s' in message) {
|
||||
const patch = unpacker.unpack(message.s);
|
||||
if ('type' in message) {
|
||||
switch (message.type) {
|
||||
case 'keys':
|
||||
unpacker.registerKeys(message.payload);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (message instanceof window.ArrayBuffer) {
|
||||
const patch = unpacker.unpack(message);
|
||||
for (const step of patch) {
|
||||
const {op, path, value} = step;
|
||||
if ('add' === op && '/selfEntity' === path) {
|
||||
|
@ -226,7 +233,6 @@ function onMessage(message) {
|
|||
}
|
||||
synchronizer.patchState(patch);
|
||||
dirty = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
socket.on('message', onMessage);
|
||||
|
|
|
@ -69,8 +69,15 @@ export class Informed extends decorate(Trait) {
|
|||
return;
|
||||
}
|
||||
// Emit!
|
||||
const keys = this._packer.computeNewKeys(steps);
|
||||
if (0 !== keys[0].length) {
|
||||
this._socket.send({
|
||||
type: 'keys',
|
||||
payload: keys,
|
||||
});
|
||||
}
|
||||
const packed = this._packer.pack(steps);
|
||||
this._socket.send({s: packed});
|
||||
this._socket.send(packed);
|
||||
},
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user