1
0
Fork 1
mirror of https://example.com synced 2024-11-23 08:46:39 +09:00
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
public send(typeOrPayload, payload?) {
const data = payload === undefined ? typeOrPayload : {
type: typeOrPayload,
body: payload
};
const type = payload === undefined ? typeOrPayload.type : typeOrPayload;
const body = payload === undefined ? typeOrPayload.body : payload;
this.stream.send('channel', {
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) {
this.pollingClock = setInterval(() => {
const crc32 = CRC32.str(this.logs.map(x => x.pos.toString()).join(''));
this.connection.send({
type: 'check',
crc32
this.connection.send('check', {
crc32: crc32
});
}, 3000);
}
@ -224,9 +223,8 @@ export default Vue.extend({
sound.play();
}
this.connection.send({
type: 'set',
pos
this.connection.send('set', {
pos: pos
});
this.checkEnd();

View file

@ -149,9 +149,9 @@ export default Vue.extend({
},
created() {
this.connection.on('change-accepts', this.onChangeAccepts);
this.connection.on('update-settings', this.onUpdateSettings);
this.connection.on('init-form', this.onInitForm);
this.connection.on('changeAccepts', this.onChangeAccepts);
this.connection.on('updateSettings', this.onUpdateSettings);
this.connection.on('initForm', this.onInitForm);
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;
@ -159,9 +159,9 @@ export default Vue.extend({
},
beforeDestroy() {
this.connection.off('change-accepts', this.onChangeAccepts);
this.connection.off('update-settings', this.onUpdateSettings);
this.connection.off('init-form', this.onInitForm);
this.connection.off('changeAccepts', this.onChangeAccepts);
this.connection.off('updateSettings', this.onUpdateSettings);
this.connection.off('initForm', this.onInitForm);
this.connection.off('message', this.onMessage);
},
@ -171,15 +171,11 @@ export default Vue.extend({
},
accept() {
this.connection.send({
type: 'accept'
});
this.connection.send('accept', {});
},
cancel() {
this.connection.send({
type: 'cancel-accept'
});
this.connection.send('cancelAccept', {});
},
onChangeAccepts(accepts) {
@ -189,8 +185,7 @@ export default Vue.extend({
},
updateSettings() {
this.connection.send({
type: 'update-settings',
this.connection.send('updateSettings', {
settings: this.game.settings
});
},
@ -216,8 +211,7 @@ export default Vue.extend({
},
onChangeForm(item) {
this.connection.send({
type: 'update-form',
this.connection.send('updateForm', {
id: item.id,
value: item.value
});
@ -238,9 +232,9 @@ export default Vue.extend({
const y = Math.floor(pos / this.game.settings.map[0].length);
const newPixel =
pixel == ' ' ? '-' :
pixel == '-' ? 'b' :
pixel == 'b' ? 'w' :
' ';
pixel == '-' ? 'b' :
pixel == 'b' ? 'w' :
' ';
const line = this.game.settings.map[y].split('');
line[x] = newPixel;
this.$set(this.game.settings.map, y, line.join(''));

View file

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

View file

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