cm-chessboard 5.5.2 → 5.5.4

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "5.5.2",
3
+ "version": "5.5.4",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
@@ -17,20 +17,28 @@ export class RenderVideo extends Extension {
17
17
  this.images = []
18
18
  this.makeSpriteInline()
19
19
  this.registerExtensionPoint(EXTENSION_POINT.animation, () => {
20
- let clonedSvgElement = this.chessboard.view.svg.cloneNode(true)
21
- let serialized = new XMLSerializer().serializeToString(clonedSvgElement)
22
- const blob = new Blob([serialized], {type: "image/svg+xml"})
23
- const blobURL = URL.createObjectURL(blob)
24
- const image = new Image()
25
- this.images.push(image)
26
- image.onload = () => {
27
- let context = this.canvas.getContext('2d')
28
- context.drawImage(image, 0, 0, this.canvas.width, this.canvas.height)
29
- this.recorder.requestData()
20
+ if(this.recorder && this.recorder.state === "recording") {
21
+ setTimeout(() => {
22
+ let clonedSvgElement = this.chessboard.view.svg.cloneNode(true)
23
+ let serialized = new XMLSerializer().serializeToString(clonedSvgElement)
24
+ const blob = new Blob([serialized], {type: "image/svg+xml"})
25
+ const blobURL = URL.createObjectURL(blob)
26
+ const image = new Image()
27
+ this.images.push(image)
28
+ image.onload = () => {
29
+ let context = this.canvas.getContext('2d')
30
+ context.drawImage(image, 0, 0, this.canvas.width, this.canvas.height)
31
+ this.recorder.requestData()
32
+ }
33
+ image.src = blobURL
34
+ })
30
35
  }
31
- image.src = blobURL
32
36
  })
33
37
  this.registerMethod("recorderStart", () => {
38
+ if(this.recorder && this.recorder.state === "recording") {
39
+ console.error("recorder is running")
40
+ return
41
+ }
34
42
  let all = document.querySelectorAll("svg *")
35
43
  for (let i = 0; i < all.length; i++) {
36
44
  this.transferComputedStyle(all[i])
@@ -57,6 +65,10 @@ export class RenderVideo extends Extension {
57
65
  * returns the url of the recorded media
58
66
  */
59
67
  this.registerMethod("recorderStop", () => {
68
+ if(!this.recorder || this.recorder.state !== "recording") {
69
+ console.error("recorder is not recording")
70
+ return
71
+ }
60
72
  this.recorder.stop()
61
73
  console.log("recorder", this.recorder.state)
62
74
  return URL.createObjectURL(new Blob(this.recordedData, {type: this.props.mediaType}))