cm-chessboard 5.5.16 → 5.5.18

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.
@@ -13,6 +13,8 @@
13
13
  <p>Works best in Chrome with webm format.</p>
14
14
  <div class="board board-small" id="board"></div>
15
15
  <video id="videoOut" controls="controls"></video>
16
+ <br/>
17
+ <a href="" style="visibility: hidden" id="download-link">Download video</a>
16
18
  <script type="module">
17
19
  import {RenderVideo} from "../../src/cm-chessboard/extensions/render-video/RenderVideo.js"
18
20
  import {Chessboard} from "../../src/cm-chessboard/Chessboard.js"
@@ -38,6 +40,8 @@
38
40
  chessboard.recorderStop().then((url) => {
39
41
  const video = document.getElementById("videoOut")
40
42
  video.src = url
43
+ document.getElementById("download-link").href = url
44
+ document.getElementById("download-link").style.visibility = "visible"
41
45
  })
42
46
 
43
47
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "5.5.16",
3
+ "version": "5.5.18",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
@@ -11,24 +11,27 @@ export class RenderVideo extends Extension {
11
11
  constructor(chessboard, props) {
12
12
  super(chessboard, props)
13
13
  this.props = {
14
- mediaType: "auto"
14
+ mediaType: "auto",
15
+ safariMode: true
15
16
  }
16
17
  Object.assign(this.props, props)
17
18
  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")) {
19
+ if(MediaRecorder.isTypeSupported("video/mp4;codecs:h264,aac")) {
20
+ this.props.mediaType = "video/mp4;codecs:h264,aac"
21
+ } else if(MediaRecorder.isTypeSupported("video/webm;codecs=h264")) {
21
22
  this.props.mediaType = "video/webm;codecs=H264"
22
23
  } else if(MediaRecorder.isTypeSupported("video/webm")) {
23
24
  this.props.mediaType = "video/webm"
24
- } else {
25
+ } else if(MediaRecorder.isTypeSupported("video/mp4")) {
26
+ this.props.mediaType = "video/mp4"
27
+ }else {
25
28
  console.error("no suitable mediaType found")
26
29
  }
27
30
  }
28
31
  console.log("recorder mediaType", this.props.mediaType)
29
32
  this.makeSpriteInline()
30
33
  this.registerExtensionPoint(EXTENSION_POINT.animation, async (event) => {
31
- if(event.event = "frame") {
34
+ if(event.event === "frame") {
32
35
  if (this.recorder && this.recorder.state === "recording") {
33
36
  await this.cloneImageAndRender()
34
37
  }
@@ -48,16 +51,17 @@ export class RenderVideo extends Extension {
48
51
  this.canvas.height = dimensions.height
49
52
  this.context = this.canvas.getContext('2d')
50
53
  document.body.append(this.canvas)
51
- /*
54
+
52
55
  this.image = new Image()
53
56
  this.image.width = this.canvas.width
54
57
  this.image.height = this.canvas.height
55
58
  this.image.style.position = "absolute"
56
59
  this.image.style.visibility = "hidden"
57
60
  document.body.append(this.image)
58
- */
59
- this.stream = this.canvas.captureStream(60)
60
- this.recorder = new MediaRecorder(this.stream, {mimeType: this.props.mediaType})
61
+
62
+ this.stream = this.canvas.captureStream(50)
63
+ this.recorder = new MediaRecorder(this.stream, {
64
+ mimeType: this.props.mediaType})
61
65
  this.recorder.ondataavailable = (event) => {
62
66
  if (event.data && event.data.size) {
63
67
  this.recordedData.push(event.data)
@@ -75,7 +79,7 @@ export class RenderVideo extends Extension {
75
79
  return
76
80
  }
77
81
  this.recordedData = []
78
- this.recorder.start()
82
+ this.recorder.start(100)
79
83
  console.log("recorder", this.recorder.state)
80
84
  resolve()
81
85
  })
@@ -112,14 +116,14 @@ export class RenderVideo extends Extension {
112
116
  }
113
117
 
114
118
  async cloneImageAndRender() {
115
- return new Promise((resolve, reject) => {
119
+ return new Promise((resolve) => {
116
120
  let serialized = new XMLSerializer().serializeToString(this.chessboard.view.svg)
117
121
  const blob = new Blob([serialized], {type: "image/svg+xml"})
118
122
  const blobURL = URL.createObjectURL(blob)
119
- const image = new Image()
123
+ // strange Safari "bug" that the content has only 300x150px
124
+ const image = this.props.safariMode ? this.image : new Image()
120
125
  image.onload = () => {
121
- this.context.drawImage(image, 0, 0, this.canvas.width, this.canvas.height)
122
- this.recorder.requestData()
126
+ this.context.drawImage(image, 0, 0, this.canvas.width, this.canvas.height, 0, 0, this.canvas.width, this.canvas.height)
123
127
  resolve()
124
128
  }
125
129
  image.src = blobURL