-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocket_record.js
49 lines (38 loc) · 1.18 KB
/
socket_record.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import SocketIo from './vj/socket/socket';
export default class SocketRecord {
constructor(fps) {
this.then = 0
this.interval = 1000 / fps
this.allowSave = true
this._isStopped = true
SocketIo.on('recorder:image:saved', () => {
this.allowSave = true
})
SocketIo.on('recorder:started', (path) => {
this._isStopped = false
})
SocketIo.on('recorder:video:saved', (path) => {
console.log(path);
})
}
stop(options = { videoWidth: 640, videoHeight: 360 }) {
this._isStopped = true
SocketIo.emit('recorder:video:save', options.videoWidth, options.videoHeight)
}
start() {
SocketIo.emit('recorder:start')
}
record(canvas) {
if (this._isStopped) {
return
}
let now = performance.now()
let delta = now - this.then;
if (delta > this.interval && this.allowSave) {
this.then = now - (delta % this.interval);
this.allowSave = false
let jpegUrl = canvas.toDataURL("image/jpeg");
SocketIo.emit('recorder:image:save', jpegUrl)
}
}
}