Closes #2855
This commit is contained in:
syuilo 2018-10-09 01:50:49 +09:00
parent 51d8de2c38
commit c6110dd996
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
5 changed files with 27 additions and 38 deletions

View File

@ -253,14 +253,13 @@ abstract class Connection extends EventEmitter {
@autobind @autobind
public send(typeOrPayload, payload?) { public send(typeOrPayload, payload?) {
const data = payload === undefined ? typeOrPayload : { const type = payload === undefined ? typeOrPayload.type : typeOrPayload;
type: typeOrPayload, const body = payload === undefined ? typeOrPayload.body : payload;
body: payload
};
this.stream.send('channel', { this.stream.send('channel', {
id: this.id, id: this.id,
body: data type: type,
body: body
}); });
} }

View File

@ -186,9 +186,8 @@ export default Vue.extend({
if (this.game.isStarted && !this.game.isEnded) { if (this.game.isStarted && !this.game.isEnded) {
this.pollingClock = setInterval(() => { this.pollingClock = setInterval(() => {
const crc32 = CRC32.str(this.logs.map(x => x.pos.toString()).join('')); const crc32 = CRC32.str(this.logs.map(x => x.pos.toString()).join(''));
this.connection.send({ this.connection.send('check', {
type: 'check', crc32: crc32
crc32
}); });
}, 3000); }, 3000);
} }
@ -224,9 +223,8 @@ export default Vue.extend({
sound.play(); sound.play();
} }
this.connection.send({ this.connection.send('set', {
type: 'set', pos: pos
pos
}); });
this.checkEnd(); this.checkEnd();

View File

@ -149,9 +149,9 @@ export default Vue.extend({
}, },
created() { created() {
this.connection.on('change-accepts', this.onChangeAccepts); this.connection.on('changeAccepts', this.onChangeAccepts);
this.connection.on('update-settings', this.onUpdateSettings); this.connection.on('updateSettings', this.onUpdateSettings);
this.connection.on('init-form', this.onInitForm); this.connection.on('initForm', this.onInitForm);
this.connection.on('message', this.onMessage); this.connection.on('message', this.onMessage);
if (this.game.user1Id != this.$store.state.i.id && this.game.settings.form1) this.form = this.game.settings.form1; if (this.game.user1Id != this.$store.state.i.id && this.game.settings.form1) this.form = this.game.settings.form1;
@ -159,9 +159,9 @@ export default Vue.extend({
}, },
beforeDestroy() { beforeDestroy() {
this.connection.off('change-accepts', this.onChangeAccepts); this.connection.off('changeAccepts', this.onChangeAccepts);
this.connection.off('update-settings', this.onUpdateSettings); this.connection.off('updateSettings', this.onUpdateSettings);
this.connection.off('init-form', this.onInitForm); this.connection.off('initForm', this.onInitForm);
this.connection.off('message', this.onMessage); this.connection.off('message', this.onMessage);
}, },
@ -171,15 +171,11 @@ export default Vue.extend({
}, },
accept() { accept() {
this.connection.send({ this.connection.send('accept', {});
type: 'accept'
});
}, },
cancel() { cancel() {
this.connection.send({ this.connection.send('cancelAccept', {});
type: 'cancel-accept'
});
}, },
onChangeAccepts(accepts) { onChangeAccepts(accepts) {
@ -189,8 +185,7 @@ export default Vue.extend({
}, },
updateSettings() { updateSettings() {
this.connection.send({ this.connection.send('updateSettings', {
type: 'update-settings',
settings: this.game.settings settings: this.game.settings
}); });
}, },
@ -216,8 +211,7 @@ export default Vue.extend({
}, },
onChangeForm(item) { onChangeForm(item) {
this.connection.send({ this.connection.send('updateForm', {
type: 'update-form',
id: item.id, id: item.id,
value: item.value value: item.value
}); });

View File

@ -174,8 +174,7 @@ export default Vue.extend({
this.messages.push(message); this.messages.push(message);
if (message.userId != this.$store.state.i.id && !document.hidden) { if (message.userId != this.$store.state.i.id && !document.hidden) {
this.connection.send({ this.connection.send('read', {
type: 'read',
id: message.id id: message.id
}); });
} }
@ -247,8 +246,7 @@ export default Vue.extend({
if (document.hidden) return; if (document.hidden) return;
this.messages.forEach(message => { this.messages.forEach(message => {
if (message.userId !== this.$store.state.i.id && !message.isRead) { if (message.userId !== this.$store.state.i.id && !message.isRead) {
this.connection.send({ this.connection.send('read', {
type: 'read',
id: message.id id: message.id
}); });
} }

View File

@ -23,10 +23,10 @@ export default class extends Channel {
public onMessage(type: string, body: any) { public onMessage(type: string, body: any) {
switch (type) { switch (type) {
case 'accept': this.accept(true); break; case 'accept': this.accept(true); break;
case 'cancel-accept': this.accept(false); break; case 'cancelAccept': this.accept(false); break;
case 'update-settings': this.updateSettings(body.settings); break; case 'updateSettings': this.updateSettings(body.settings); break;
case 'init-form': this.initForm(body); break; case 'initForm': this.initForm(body); break;
case 'update-form': this.updateForm(body.id, body.value); break; case 'updateForm': this.updateForm(body.id, body.value); break;
case 'message': this.message(body); break; case 'message': this.message(body); break;
case 'set': this.set(body.pos); break; case 'set': this.set(body.pos); break;
case 'check': this.check(body.crc32); break; case 'check': this.check(body.crc32); break;