Skip to content

Commit

Permalink
fix: 受信確認を行いながらchank送信を行う
Browse files Browse the repository at this point in the history
データ送信は送信順序を維持する為、ネットワーク遅延がある環境でchankを一気に送信すると、後続のデータ送信が詰まる。
この問題の回避のため、受信側からの送信継続要求を受けつつchank送信を制御する。
  • Loading branch information
TK11235 committed Oct 3, 2018
1 parent 19ad16e commit f83cc5b
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/app/class/core/file-storage/audio-sharing-task.ts
Expand Up @@ -16,6 +16,9 @@ export class AudioSharingTask {
private chankSize: number = 14 * 1024;
private sendChankTimer: NodeJS.Timer;

private sentChankLength = 0;
private completedChankLength = 0;

get identifier(): string { return this.file.identifier; }

onfinish: (task: AudioSharingTask) => void;
Expand Down Expand Up @@ -60,7 +63,19 @@ export class AudioSharingTask {
offset += this.chankSize;
}
let blob = new Blob(this.chanks, { type: this.file.blob.type });
console.warn('ファイル末尾 ', this.chanks);
console.log('チャンク分割 ' + this.file.identifier, this.chanks.length);

EventSystem.register(this)
.on<number>('FILE_MORE_CHANK_' + this.file.identifier, 0, event => {
if (this.sendTo !== event.sendFrom) return;
this.completedChankLength = event.data;
if (this.sendChankTimer == null) {
clearTimeout(this.timeoutTimer);
this.sendChank(this.sentChankLength);
}
});

this.sentChankLength = this.completedChankLength = 0;
this.sendChank(0);
}

Expand All @@ -73,12 +88,18 @@ export class AudioSharingTask {
/* */

EventSystem.call('FILE_SEND_CHANK_' + this.file.identifier, data, this.sendTo);
if (index + 1 < this.chanks.length) {
this.sentChankLength = index;
if (this.completedChankLength + 16 <= index + 1) {
console.log('waitSendChank... ', this.completedChankLength);
this.sendChankTimer = null;
this.setTimeout();
} else if (index + 1 < this.chanks.length) {
this.sendChank(index + 1);
} else {
EventSystem.call('FILE_SEND_END_' + this.file.identifier, { type: this.file.blob.type }, this.sendTo);
console.warn('ファイル送信完了', this.file);
if (this.onfinish) this.onfinish(this);
this.cancel();
}
}, 0);
}
Expand All @@ -95,6 +116,9 @@ export class AudioSharingTask {
/* */

this.setTimeout();
if ((event.data.index + 1) % 8 === 0) {
EventSystem.call('FILE_MORE_CHANK_' + this.file.identifier, event.data.index + 1, event.sendFrom);
}
}).on('FILE_SEND_END_' + this.file.identifier, 0, event => {
if (this.timeoutTimer) clearTimeout(this.timeoutTimer);
EventSystem.unregister(this);
Expand Down

0 comments on commit f83cc5b

Please sign in to comment.