cm-chessboard 5.5.13 → 5.5.15
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.
package/package.json
CHANGED
|
@@ -29,11 +29,11 @@ export class RenderVideo extends Extension {
|
|
|
29
29
|
this.image = new Image()
|
|
30
30
|
document.body.append(this.image)
|
|
31
31
|
this.makeSpriteInline()
|
|
32
|
-
this.registerExtensionPoint(EXTENSION_POINT.animation, () => {
|
|
33
|
-
if
|
|
34
|
-
|
|
35
|
-
this.cloneImageAndRender()
|
|
36
|
-
}
|
|
32
|
+
this.registerExtensionPoint(EXTENSION_POINT.animation, async (event) => {
|
|
33
|
+
if(event.event = "frame") {
|
|
34
|
+
if (this.recorder && this.recorder.state === "recording") {
|
|
35
|
+
await this.cloneImageAndRender()
|
|
36
|
+
}
|
|
37
37
|
}
|
|
38
38
|
})
|
|
39
39
|
this.registerMethod("recorderInit", () => {
|
|
@@ -58,7 +58,7 @@ export class RenderVideo extends Extension {
|
|
|
58
58
|
this.image.style.visibility = "hidden"
|
|
59
59
|
document.body.append(this.image)
|
|
60
60
|
|
|
61
|
-
this.stream = this.canvas.captureStream()
|
|
61
|
+
this.stream = this.canvas.captureStream(60)
|
|
62
62
|
this.recorder = new MediaRecorder(this.stream, {mimeType: this.props.mediaType})
|
|
63
63
|
this.recorder.ondataavailable = (event) => {
|
|
64
64
|
if (event.data && event.data.size) {
|
|
@@ -86,11 +86,11 @@ export class RenderVideo extends Extension {
|
|
|
86
86
|
* returns the url of the recorded media
|
|
87
87
|
*/
|
|
88
88
|
this.registerMethod("recorderStop", () => {
|
|
89
|
-
return new Promise((resolve, reject) => {
|
|
89
|
+
return new Promise(async (resolve, reject) => {
|
|
90
90
|
if (!this.recorder || this.recorder.state !== "recording") {
|
|
91
91
|
reject("recorder is not recording")
|
|
92
92
|
}
|
|
93
|
-
this.cloneImageAndRender()
|
|
93
|
+
await this.cloneImageAndRender()
|
|
94
94
|
setTimeout(() => {
|
|
95
95
|
this.recorder.stop()
|
|
96
96
|
console.log("recorder", this.recorder.state)
|
|
@@ -99,34 +99,37 @@ export class RenderVideo extends Extension {
|
|
|
99
99
|
})
|
|
100
100
|
})
|
|
101
101
|
this.registerMethod("recorderPause", (ms) => {
|
|
102
|
-
return new Promise((resolve) => {
|
|
103
|
-
this.cloneImageAndRender()
|
|
104
|
-
const interval = setInterval(() => {
|
|
105
|
-
this.cloneImageAndRender()
|
|
106
|
-
},
|
|
107
|
-
setTimeout(() => {
|
|
102
|
+
return new Promise(async (resolve) => {
|
|
103
|
+
await this.cloneImageAndRender()
|
|
104
|
+
const interval = setInterval(async () => {
|
|
105
|
+
await this.cloneImageAndRender()
|
|
106
|
+
}, 50)
|
|
107
|
+
setTimeout(async () => {
|
|
108
108
|
clearInterval(interval)
|
|
109
|
-
this.cloneImageAndRender()
|
|
109
|
+
await this.cloneImageAndRender()
|
|
110
110
|
resolve()
|
|
111
111
|
}, ms)
|
|
112
112
|
})
|
|
113
113
|
})
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
cloneImageAndRender() {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
this.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
116
|
+
async cloneImageAndRender() {
|
|
117
|
+
return new Promise((resolve, reject) => {
|
|
118
|
+
if(this.rendering) {
|
|
119
|
+
resolve()
|
|
120
|
+
}
|
|
121
|
+
this.rendering = true
|
|
122
|
+
let serialized = new XMLSerializer().serializeToString(this.chessboard.view.svg)
|
|
123
|
+
const blob = new Blob([serialized], {type: "image/svg+xml"})
|
|
124
|
+
const blobURL = URL.createObjectURL(blob)
|
|
125
|
+
this.image.onload = () => {
|
|
126
|
+
this.context.drawImage(this.image, 0, 0, this.canvas.width, this.canvas.height, 0, 0, this.canvas.width, this.canvas.height)
|
|
127
|
+
this.recorder.requestData()
|
|
128
|
+
this.rendering = false
|
|
129
|
+
resolve()
|
|
130
|
+
}
|
|
131
|
+
this.image.src = blobURL
|
|
132
|
+
})
|
|
130
133
|
}
|
|
131
134
|
|
|
132
135
|
transferComputedStyle(element) {
|