cm-chessboard 5.5.9 → 5.5.10
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,9 +10,9 @@
|
|
|
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
|
-
<video id="videoOut" controls="controls"></video>
|
|
15
|
+
<video id="videoOut" controls="controls" style="width: 320px; height: 320px"></video>
|
|
16
16
|
<script type="module">
|
|
17
17
|
import {RenderVideo} from "../../src/cm-chessboard/extensions/render-video/RenderVideo.js"
|
|
18
18
|
import {Chessboard} from "../../src/cm-chessboard/Chessboard.js"
|
|
@@ -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,24 @@ 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
|
+
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)
|
|
17
29
|
this.images = []
|
|
18
30
|
this.makeSpriteInline()
|
|
19
31
|
this.registerExtensionPoint(EXTENSION_POINT.animation, (event) => {
|
|
20
|
-
// console.log(event)
|
|
21
32
|
if (this.recorder && this.recorder.state === "recording") {
|
|
22
33
|
setTimeout(() => {
|
|
23
34
|
this.cloneImageAndRender()
|
|
@@ -35,6 +46,7 @@ export class RenderVideo extends Extension {
|
|
|
35
46
|
}
|
|
36
47
|
const dimensions = this.chessboard.view.svg.getBBox()
|
|
37
48
|
this.canvas = document.createElement("canvas")
|
|
49
|
+
this.canvas.style.backgroundColor = "#000"
|
|
38
50
|
this.canvas.style.display = "none"
|
|
39
51
|
this.canvas.width = dimensions.width
|
|
40
52
|
this.canvas.height = dimensions.height
|
|
@@ -76,10 +88,17 @@ export class RenderVideo extends Extension {
|
|
|
76
88
|
let serialized = new XMLSerializer().serializeToString(this.chessboard.view.svg)
|
|
77
89
|
const blob = new Blob([serialized], {type: "image/svg+xml"})
|
|
78
90
|
const blobURL = URL.createObjectURL(blob)
|
|
91
|
+
// console.log(blobURL)
|
|
79
92
|
const image = new Image()
|
|
93
|
+
// needed for safari
|
|
94
|
+
image.width = this.canvas.width
|
|
95
|
+
image.height = this.canvas.height
|
|
96
|
+
image.style.position = "absolute"
|
|
97
|
+
image.style.visibility = "hidden"
|
|
98
|
+
//
|
|
99
|
+
document.body.append(image)
|
|
80
100
|
image.onload = () => {
|
|
81
|
-
this.contect.drawImage(image, 0, 0, this.canvas.width, this.canvas.height)
|
|
82
|
-
this.recorder.requestData()
|
|
101
|
+
this.contect.drawImage(image, 0, 0, this.canvas.width, this.canvas.height, 0, 0, this.canvas.width, this.canvas.height)
|
|
83
102
|
}
|
|
84
103
|
image.src = blobURL
|
|
85
104
|
}
|