[Client] Fix bug, some refactorings

This commit is contained in:
syuilo 2017-03-20 14:35:00 +09:00
parent 7eeb9c4962
commit de5dc87cec
3 changed files with 30 additions and 16 deletions

View file

@ -45,6 +45,8 @@ class Connection {
} }
send(message) { send(message) {
// TODO: バッファリングしてつぎ接続した時に送信する
if (this.state != 'connected') return;
this.socket.send(JSON.stringify(message)); this.socket.send(JSON.stringify(message));
} }

View file

@ -364,13 +364,24 @@
} }
}; };
this.on('mount', () => { this.capture = () => {
this.stream.send({ this.stream.send({
type: 'capture', type: 'capture',
id: this.p.id id: this.p.id
}); });
this.stream.event.on('post-updated', this.onStreamPostUpdated); this.stream.event.on('post-updated', this.onStreamPostUpdated);
};
this.decapture = () => {
this.stream.send({
type: 'decapture',
id: this.p.id
});
this.stream.event.off('post-updated', this.onStreamPostUpdated);
};
this.on('mount', () => {
this.capture();
if (this.p.text) { if (this.p.text) {
const tokens = this.p.ast; const tokens = this.p.ast;
@ -393,12 +404,7 @@
}); });
this.on('unmount', () => { this.on('unmount', () => {
this.stream.send({ this.decapture();
type: 'decapture',
id: this.p.id
});
this.stream.event.off('post-updated', this.onStreamPostUpdated);
}); });
this.reply = () => { this.reply = () => {

View file

@ -340,13 +340,24 @@
} }
}; };
this.on('mount', () => { this.capture = () => {
this.stream.send({ this.stream.send({
type: 'capture', type: 'capture',
id: this.p.id id: this.p.id
}); });
this.stream.event.on('post-updated', this.onStreamPostUpdated); this.stream.event.on('post-updated', this.onStreamPostUpdated);
};
this.decapture = () => {
this.stream.send({
type: 'decapture',
id: this.p.id
});
this.stream.event.off('post-updated', this.onStreamPostUpdated);
};
this.on('mount', () => {
this.capture();
if (this.p.text) { if (this.p.text) {
const tokens = this.p.ast; const tokens = this.p.ast;
@ -369,12 +380,7 @@
}); });
this.on('unmount', () => { this.on('unmount', () => {
this.stream.send({ this.decapture();
type: 'decapture',
id: this.p.id
});
this.stream.event.off('post-updated', this.onStreamPostUpdated);
}); });
this.reply = () => { this.reply = () => {