-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
138 lines (110 loc) · 3.86 KB
/
app.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*const player = document.querySelector('#player');
const handleSuccess = (stream) => {
if(window.URL){
player.srcObject = stream;
} else {
player.src = stream;
}
}*/
import idb from '/idb.js';
const model = {
init() {
this.player = document.getElementById('player');
this.downloadLink = document.getElementById('download');
this.stopButton = document.getElementById('stop');
this.startButton = document.getElementById('start');
this.pauseButton = document.getElementById('pause');
this.titleInput = document.getElementById('videoTitle');
this.comentInput = document.getElementById('videoComent');
if (!window.indexedDB) {
console.log("Your browser doesn't support a stable version of IndexedDB. Such and such feature will not be available.");
}else{
/*window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
// DON'T use "var indexedDB = ..." if you're not in a function.
// Moreover, you may need references to some window.IDB* objects:
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction;
window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange;
// (Mozilla has never prefixed these objects, so we don't need window.mozIDB*)
//let us open our database
const DBOpenReq = indexedDB.open("MemoriesDataBase", 4);
//let handle error
*/
idb.getDb();
this.getVideoDataFromIDB();
}
},
getVideoDataFromIDB() {
idb.getAllData().then(data => console.log(data));
},
saveVideoDataToIDB() {
},
handleSuccess: function(stream) {
const options = {mimeType: 'video/webm;codecs=vp9,opus'};
let recordedChunks;
const mediaRecorder = new MediaRecorder(stream, options);
mediaRecorder.addEventListener('dataavailable', function(e) {
if (e.data.size > 0) {
recordedChunks = e.data;
}
console.log(recordedChunks);
});
mediaRecorder.addEventListener('start', function() {
console.log("start", mediaRecorder.state);
});
mediaRecorder.addEventListener('pause', function() {
console.log("pause", mediaRecorder.state);
});
mediaRecorder.addEventListener('resume', function() {
console.log("resume", mediaRecorder.state);
});
mediaRecorder.addEventListener('stop', function() {
const mem = {
title: model.titleInput.value,
date: new Date().toUTCString(),
coment:model.comentInput.value,
video: recordedChunks
};
console.log("stop");
idb.saveData(mem);
model.downloadLink.href = URL.createObjectURL(mem.video);
model.downloadLink.download = 'acetest.webm';
});
model.stopButton.addEventListener('click', function() {
mediaRecorder.stop();
model.titleInput.value = '';
model.comentInput.value = '';
})
model.startButton.addEventListener('click', function() {
mediaRecorder.start();
})
model.pauseButton.addEventListener('click', function() {
if(model.pauseButton.classList.contains('pause')){
model.pauseButton.classList.remove('pause');
model.pauseButton.classList.add('resume');
mediaRecorder.resume();
}else if(model.pauseButton.classList.contains('resume')){
model.pauseButton.classList.remove('resume');
model.pauseButton.classList.add('pause');
mediaRecorder.pause();
}
})
model.player.srcObject = stream;
}
}
const octopuss = {
init() {
model.init();
const constraints = {
audio:false,
video: true
};
navigator.mediaDevices
.getUserMedia(constraints)
.then(model.handleSuccess);
}
}
const display = {
}
window.addEventListener('load', () => {
octopuss.init();
})