Skip to content

Commit

Permalink
WebSocketの送信処理で重複している部分をリファクタリング
Browse files Browse the repository at this point in the history
  • Loading branch information
onozaty committed Feb 12, 2018
1 parent 14ab5c0 commit 81f126a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions shared-camera-server/src/main/resources/static/shared-camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ class SharedCamera {
}

setTimeout(() => {
if (this._webSocket && this._webSocket.readyState == 1) { // 1: OPEN
this._webSocket.send(new Blob());
}
this._send(new Blob());
}, 100);
}

Expand All @@ -76,11 +74,11 @@ class SharedCamera {
}

this._timerId = setInterval(() => {
this._send(video, transferSetting.quality);
this._sendImage(video, transferSetting.quality);
}, transferSetting.interval);
}

_send(video, quality) {
_sendImage(video, quality) {
if (!this._webSocket) {
return;
}
Expand All @@ -92,12 +90,18 @@ class SharedCamera {
canvas.setAttribute('height', video.videoHeight);
context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
canvas.toBlob((blob) => {
if (blob && this._webSocket && this._webSocket.readyState == 1) { // 1: OPEN
this._webSocket.send(blob);
if (blob) {
this._send(blob);
}
}, 'image/jpeg', quality);
}

_send(data) {
if (this._webSocket && this._webSocket.readyState == 1) { // 1: OPEN
this._webSocket.send(data);
}
}

_onOpen() {
if (this._handlers.open) {
this._handlers.open();
Expand Down

0 comments on commit 81f126a

Please sign in to comment.