cm-chessboard 5.5.9 → 5.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<body>
|
|
11
11
|
<h1><a href="../..">cm-chessboard</a></h1>
|
|
12
12
|
<h2>Example: RenderVideo extension</h2>
|
|
13
|
-
<p>Works in Chrome.</p>
|
|
13
|
+
<p>Works in Chrome (webm) and Safari (mp4).</p>
|
|
14
14
|
<div class="board board-small" id="board"></div>
|
|
15
15
|
<video id="videoOut" controls="controls"></video>
|
|
16
16
|
<script type="module">
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
})
|
|
43
43
|
}, 400)
|
|
44
44
|
})
|
|
45
|
-
},
|
|
45
|
+
}, 250)
|
|
46
46
|
</script>
|
|
47
47
|
</body>
|
|
48
48
|
</html>
|
package/package.json
CHANGED
|
@@ -11,13 +11,25 @@ export class RenderVideo extends Extension {
|
|
|
11
11
|
constructor(chessboard, props) {
|
|
12
12
|
super(chessboard, props)
|
|
13
13
|
this.props = {
|
|
14
|
-
mediaType: "
|
|
14
|
+
mediaType: "auto"
|
|
15
15
|
}
|
|
16
16
|
Object.assign(this.props, props)
|
|
17
|
-
this.
|
|
17
|
+
if(this.props.mediaType === "auto") {
|
|
18
|
+
if(MediaRecorder.isTypeSupported("video/mp4")) {
|
|
19
|
+
this.props.mediaType = "video/mp4"
|
|
20
|
+
} else if(MediaRecorder.isTypeSupported("video/webm;codecs=H264")) {
|
|
21
|
+
this.props.mediaType = "video/webm;codecs=H264"
|
|
22
|
+
} else if(MediaRecorder.isTypeSupported("video/webm")) {
|
|
23
|
+
this.props.mediaType = "video/webm"
|
|
24
|
+
} else {
|
|
25
|
+
console.error("no suitable mediaType found")
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
console.log("recorder mediaType", this.props.mediaType)
|
|
29
|
+
this.image = new Image()
|
|
30
|
+
document.body.append(this.image)
|
|
18
31
|
this.makeSpriteInline()
|
|
19
32
|
this.registerExtensionPoint(EXTENSION_POINT.animation, (event) => {
|
|
20
|
-
// console.log(event)
|
|
21
33
|
if (this.recorder && this.recorder.state === "recording") {
|
|
22
34
|
setTimeout(() => {
|
|
23
35
|
this.cloneImageAndRender()
|
|
@@ -35,10 +47,19 @@ export class RenderVideo extends Extension {
|
|
|
35
47
|
}
|
|
36
48
|
const dimensions = this.chessboard.view.svg.getBBox()
|
|
37
49
|
this.canvas = document.createElement("canvas")
|
|
50
|
+
this.canvas.style.backgroundColor = "#000"
|
|
38
51
|
this.canvas.style.display = "none"
|
|
39
52
|
this.canvas.width = dimensions.width
|
|
40
53
|
this.canvas.height = dimensions.height
|
|
41
54
|
this.contect = this.canvas.getContext('2d')
|
|
55
|
+
|
|
56
|
+
this.image = new Image()
|
|
57
|
+
this.image.width = this.canvas.width
|
|
58
|
+
this.image.height = this.canvas.height
|
|
59
|
+
this.image.style.position = "absolute"
|
|
60
|
+
this.image.style.visibility = "hidden"
|
|
61
|
+
document.body.append(this.image)
|
|
62
|
+
|
|
42
63
|
document.body.append(this.canvas)
|
|
43
64
|
this.stream = this.canvas.captureStream()
|
|
44
65
|
this.recorder = new MediaRecorder(this.stream, {mimeType: this.props.mediaType})
|
|
@@ -67,7 +88,7 @@ export class RenderVideo extends Extension {
|
|
|
67
88
|
this.recorder.stop()
|
|
68
89
|
console.log("recorder", this.recorder.state)
|
|
69
90
|
resolve(URL.createObjectURL(new Blob(this.recordedData, {type: this.props.mediaType})))
|
|
70
|
-
},
|
|
91
|
+
}, 200)
|
|
71
92
|
})
|
|
72
93
|
})
|
|
73
94
|
}
|
|
@@ -76,12 +97,10 @@ export class RenderVideo extends Extension {
|
|
|
76
97
|
let serialized = new XMLSerializer().serializeToString(this.chessboard.view.svg)
|
|
77
98
|
const blob = new Blob([serialized], {type: "image/svg+xml"})
|
|
78
99
|
const blobURL = URL.createObjectURL(blob)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this.contect.drawImage(image, 0, 0, this.canvas.width, this.canvas.height)
|
|
82
|
-
this.recorder.requestData()
|
|
100
|
+
this.image.onload = () => {
|
|
101
|
+
this.contect.drawImage(this.image, 0, 0, this.canvas.width, this.canvas.height, 0, 0, this.canvas.width, this.canvas.height)
|
|
83
102
|
}
|
|
84
|
-
image.src = blobURL
|
|
103
|
+
this.image.src = blobURL
|
|
85
104
|
}
|
|
86
105
|
|
|
87
106
|
transferComputedStyle(element) {
|