polotno-node 2.6.5 → 2.6.7

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.
Files changed (3) hide show
  1. package/README.md +8 -1
  2. package/instance.js +18 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -245,9 +245,16 @@ const url = await instance.run(async (json) => {
245
245
 
246
246
  **This part is currently under development and API will change.**
247
247
 
248
+ You may need to have ffmpeg available in your system to make it work.
249
+ Also you need to manually dependencies:
250
+
251
+ ```bash
252
+ npm install fluent-ffmpeg axios
253
+ ```
254
+
248
255
  ```js
249
256
  import { createInstance } from 'polotno-node';
250
- import { jsonToVideo } from 'polotno/video';
257
+ import { jsonToVideo } from 'polotno-node/video';
251
258
 
252
259
  // create working instance
253
260
  const instance = await createInstance({
package/instance.js CHANGED
@@ -73,6 +73,8 @@ module.exports.jsonToBlob = async (page, json, attrs) => {
73
73
  );
74
74
  };
75
75
 
76
+ const busyPages = [];
77
+
76
78
  module.exports.createInstance = async ({
77
79
  key,
78
80
  url,
@@ -89,6 +91,14 @@ module.exports.createInstance = async ({
89
91
  ? await module.exports.createPage(browser, visitPage)
90
92
  : firstPage;
91
93
 
94
+ if (busyPages.indexOf(page) >= 0) {
95
+ throw new Error(
96
+ 'Current rendering context is busy with another task. Please use `useParallelPages: true` option to run multiple tasks in parallel or make sure previous task is finished before starting a new one.'
97
+ );
98
+ }
99
+
100
+ busyPages.push(page);
101
+
92
102
  try {
93
103
  if (args[1]?.assetLoadTimeout) {
94
104
  await page.evaluate((timeout) => {
@@ -124,6 +134,10 @@ module.exports.createInstance = async ({
124
134
  const result = await page.evaluate(func, ...args);
125
135
  const error = await page.evaluate(() => window._polotnoError);
126
136
  if (error) {
137
+ // clear error
138
+ await page.evaluate(() => {
139
+ window._polotnoError = null;
140
+ });
127
141
  const message = error.toString();
128
142
  const isFontError = message.indexOf('Timeout for loading font') >= 0;
129
143
  const skipError = isFontError && args[1]?.skipFontError;
@@ -131,11 +145,15 @@ module.exports.createInstance = async ({
131
145
  throw new Error(error);
132
146
  }
133
147
  }
148
+ // remove busy page
149
+ busyPages.splice(busyPages.indexOf(page), 1);
134
150
  if (useParallelPages) {
135
151
  await page.close();
136
152
  }
137
153
  return result;
138
154
  } catch (e) {
155
+ // remove busy page
156
+ busyPages.splice(busyPages.indexOf(page), 1);
139
157
  if (useParallelPages) {
140
158
  await page.close();
141
159
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polotno-node",
3
- "version": "2.6.5",
3
+ "version": "2.6.7",
4
4
  "description": "Polotno workflow from NodeJS",
5
5
  "main": "index.js",
6
6
  "scripts": {