@theia/electron 1.22.0-next.6 → 1.22.0

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/README.in.md ADDED
@@ -0,0 +1,41 @@
1
+ <div align='center'>
2
+
3
+ <br />
4
+
5
+ <img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' />
6
+
7
+ <h2>ECLIPSE THEIA - ELECTRON EXTENSION</h2>
8
+
9
+ <hr />
10
+
11
+ </div>
12
+
13
+ ## Description
14
+
15
+ The `@theia/electron` extension bundles all Electron-specific dependencies and core functionalities.
16
+
17
+ ## Re-Exports
18
+
19
+ {{#reExportsDirectories}}
20
+ - `@theia/electron/{{&directory}}/...`
21
+ {{#packages}}
22
+ {{#modules}}
23
+ - `{{&moduleName}}` (from [`{{&packageName}}@{{&versionRange}}`]({{&npmUrl}}))
24
+ {{/modules}}
25
+ {{/packages}}
26
+ {{/reExportsDirectories}}
27
+
28
+ ## Additional Information
29
+
30
+ - [API documentation for `@theia/electron`](https://eclipse-theia.github.io/theia/docs/next/modules/electron.html)
31
+ - [Theia - GitHub](https://github.com/eclipse-theia/theia)
32
+ - [Theia - Website](https://theia-ide.org/)
33
+
34
+ ## License
35
+
36
+ - [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
37
+ - [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
38
+
39
+ ## Trademark
40
+ "Theia" is a trademark of the Eclipse Foundation
41
+ https://www.eclipse.org/theia
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  <img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' />
6
6
 
7
- <h2>ECLIPSE THEIA - ELECTRON</h2>
7
+ <h2>ECLIPSE THEIA - ELECTRON EXTENSION</h2>
8
8
 
9
9
  <hr />
10
10
 
@@ -12,30 +12,21 @@
12
12
 
13
13
  ## Description
14
14
 
15
- The `@theia/electron` extension provides runtime dependencies for Theia. The `@theia/electron` package is mandatory for any `electron` [application
16
- target](dev-packages/cli/README.md#build-target).
15
+ The `@theia/electron` extension bundles all Electron-specific dependencies and core functionalities.
17
16
 
18
- The extension includes the following commands:
17
+ ## Re-Exports
19
18
 
20
- - `npx electron-replace-ffmpeg [--help]`
21
- - `npx electron-codecs-test [--help]`
22
-
23
- Both scripts will be triggered on post-install, targeting the current
24
- architecture and "closest" Electron installation (in `node_modules`).
25
-
26
- The post-install scripts can be skipped by setting an environment variable:
27
-
28
- - Mac/Linux: `export THEIA_ELECTRON_SKIP_REPLACE_FFMPEG=1`
29
- - Windows (cmd): `set THEIA_ELECTRON_SKIP_REPLACE_FFMPEG=1`
30
- - Windows (ps): `$env:THEIA_ELECTRON_SKIP_REPLACE_FFMPEG=1`
31
-
32
- ## Re-exports
33
-
34
- - `electron` through `@theia/electron`
35
- - `native-keymap` through `@theia/electron/native-keymap`
19
+ - `@theia/electron/shared/...`
20
+ - `@electron/remote` (from [`@electron/remote@^2.0.1`](https://www.npmjs.com/package/@electron/remote))
21
+ - `@electron/remote/main` (from [`@electron/remote@^2.0.1`](https://www.npmjs.com/package/@electron/remote))
22
+ - `native-keymap` (from [`native-keymap@^2.2.1`](https://www.npmjs.com/package/native-keymap))
23
+ - `electron` (from [`electron@^15.3.5`](https://www.npmjs.com/package/electron))
24
+ - `electron-store` (from [`electron-store@^8.0.0`](https://www.npmjs.com/package/electron-store))
25
+ - `fix-path` (from [`fix-path@^3.0.0`](https://www.npmjs.com/package/fix-path))
36
26
 
37
27
  ## Additional Information
38
28
 
29
+ - [API documentation for `@theia/electron`](https://eclipse-theia.github.io/theia/docs/next/modules/electron.html)
39
30
  - [Theia - GitHub](https://github.com/eclipse-theia/theia)
40
31
  - [Theia - Website](https://theia-ide.org/)
41
32
 
package/package.json CHANGED
@@ -1,10 +1,41 @@
1
1
  {
2
2
  "name": "@theia/electron",
3
- "version": "1.22.0-next.6+8083f76b4f4",
4
- "description": "Electron runtime dependencies for Theia",
3
+ "version": "1.22.0",
4
+ "description": "Theia - Electron utility package",
5
+ "dependencies": {
6
+ "@electron/remote": "^2.0.1",
7
+ "electron-store": "^8.0.0",
8
+ "fix-path": "^3.0.0",
9
+ "native-keymap": "^2.2.1"
10
+ },
11
+ "devDependencies": {
12
+ "@theia/ext-scripts": "1.22.0",
13
+ "@theia/re-exports": "1.22.0"
14
+ },
15
+ "peerDependencies": {
16
+ "electron": "^15.3.5"
17
+ },
18
+ "theiaReExports": {
19
+ "shared": {
20
+ "export *": [
21
+ "@electron/remote",
22
+ "@electron/remote/main",
23
+ "native-keymap"
24
+ ],
25
+ "export =": [
26
+ "electron as Electron",
27
+ "electron-store as ElectronStore",
28
+ "fix-path as fixPath"
29
+ ]
30
+ }
31
+ },
5
32
  "publishConfig": {
6
33
  "access": "public"
7
34
  },
35
+ "theiaExtensions": [],
36
+ "keywords": [
37
+ "theia-extension"
38
+ ],
8
39
  "license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0",
9
40
  "repository": {
10
41
  "type": "git",
@@ -15,31 +46,21 @@
15
46
  },
16
47
  "homepage": "https://github.com/eclipse-theia/theia",
17
48
  "files": [
18
- "native/src",
19
- "native/binding.gyp",
20
- "scripts",
21
- "*.js",
22
- "*.d.ts",
23
- "!.eslintrc.js"
49
+ "lib",
50
+ "src"
24
51
  ],
25
- "bin": {
26
- "electron": "electron-cli.js",
27
- "electron-codecs-test": "electron-codecs-test.js",
28
- "electron-replace-ffmpeg": "electron-replace-ffmpeg.js"
29
- },
30
- "dependencies": {
31
- "@electron/get": "^1.12.4",
32
- "electron": "^9.0.2",
33
- "electron-store": "^5.1.1",
34
- "fix-path": "^3.0.0",
35
- "native-keymap": "^2.1.2",
36
- "node-gyp": "^7.0.0",
37
- "unzipper": "^0.9.11",
38
- "yargs": "^15.3.1"
39
- },
40
52
  "scripts": {
41
- "postinstall": "node scripts/post-install.js",
42
- "test": "mocha \"tests/**/*.spec.js\""
53
+ "generate-theia-re-exports": "theia-re-exports generate && theia-re-exports template README.in.md > README.md",
54
+ "prepare": "yarn -s generate-theia-re-exports",
55
+ "lint": "echo skip || theiaext lint",
56
+ "build": "echo skip || theiaext build",
57
+ "watch": "echo skip || theiaext watch",
58
+ "clean": "echo skip || theiaext clean",
59
+ "test": "echo skip || theiaext test",
60
+ "version": "yarn -s generate-theia-re-exports"
61
+ },
62
+ "nyc": {
63
+ "extends": "../../configs/nyc.json"
43
64
  },
44
- "gitHead": "8083f76b4f4969bad12549ebba0a2c1df9591552"
65
+ "gitHead": "84cfe06b4b10720cc9915bc6e2f091a2b09b1087"
45
66
  }
package/electron-cli.js DELETED
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env node
2
- /********************************************************************************
3
- * Copyright (C) 2019 TypeFox and others.
4
- *
5
- * This program and the accompanying materials are made available under the
6
- * terms of the Eclipse Public License v. 2.0 which is available at
7
- * http://www.eclipse.org/legal/epl-2.0.
8
- *
9
- * This Source Code may also be made available under the following Secondary
10
- * Licenses when the conditions for such availability set forth in the Eclipse
11
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- * with the GNU Classpath Exception which is available at
13
- * https://www.gnu.org/software/classpath/license.html.
14
- *
15
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- ********************************************************************************/
17
-
18
- require('electron/cli.js');
@@ -1,73 +0,0 @@
1
- #!/usr/bin/env node
2
- /********************************************************************************
3
- * Copyright (C) 2019 Ericsson and others.
4
- *
5
- * This program and the accompanying materials are made available under the
6
- * terms of the Eclipse Public License v. 2.0 which is available at
7
- * http://www.eclipse.org/legal/epl-2.0.
8
- *
9
- * This Source Code may also be made available under the following Secondary
10
- * Licenses when the conditions for such availability set forth in the Eclipse
11
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- * with the GNU Classpath Exception which is available at
13
- * https://www.gnu.org/software/classpath/license.html.
14
- *
15
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- ********************************************************************************/
17
- 'use-strict'
18
-
19
- // @ts-check
20
-
21
- const yargs = require('yargs');
22
-
23
- const { platforms, libffmpegCodecs, libffmpegAbsolutePath } = require('./electron-ffmpeg-lib');
24
-
25
- const bad = new Set([
26
- 'h264',
27
- 'aac',
28
- ]);
29
-
30
- async function main() {
31
- const options = yargs
32
- .option('absolutePath', {
33
- alias: 'a',
34
- description: 'Absolute path to the ffmpeg shared library.',
35
- })
36
- .option('electronDist', {
37
- alias: 'd',
38
- description: 'Electron distribution location.',
39
- })
40
- .option('platform', {
41
- alias: 'p',
42
- description: 'Dictates where the library is located within the Electron distribution.',
43
- choices: platforms,
44
- })
45
- .help().alias('h', 'help')
46
- .exitProcess(false)
47
- .argv;
48
-
49
- if (options.help) {
50
- return; // help is being displayed.
51
- }
52
- const libraryPath = options['absolutePath'] || libffmpegAbsolutePath({
53
- electronDist: options['electronDist'],
54
- platform: options['platform'],
55
- });
56
- const codecs = libffmpegCodecs(libraryPath);
57
- const found = [];
58
- for (const codec of codecs) {
59
- if (bad.has(codec.name.toLowerCase())) {
60
- found.push(codec);
61
- }
62
- }
63
- if (found.length > 0) {
64
- throw new Error(`${found.length} bad / ${codecs.length} found\n${
65
- found.map(codec => `> ${codec.name} detected (${codec.longName})`).join('\n')}`);
66
- }
67
- console.info(`"${libraryPath}" does not contain proprietary codecs (${codecs.length} found).`);
68
- }
69
-
70
- main().catch(error => {
71
- console.error(error);
72
- process.exit(error.code || 127);
73
- })
@@ -1,130 +0,0 @@
1
- #!/usr/bin/env node
2
- /********************************************************************************
3
- * Copyright (C) 2019 Ericsson and others.
4
- *
5
- * This program and the accompanying materials are made available under the
6
- * terms of the Eclipse Public License v. 2.0 which is available at
7
- * http://www.eclipse.org/legal/epl-2.0.
8
- *
9
- * This Source Code may also be made available under the following Secondary
10
- * Licenses when the conditions for such availability set forth in the Eclipse
11
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- * with the GNU Classpath Exception which is available at
13
- * https://www.gnu.org/software/classpath/license.html.
14
- *
15
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- ********************************************************************************/
17
- 'use-strict'
18
-
19
- // @ts-check
20
-
21
- const crypto = require('crypto');
22
- const path = require('path');
23
- const fs = require('fs');
24
-
25
- const ffmpeg = require('./native/build/Release/ffmpeg.node');
26
-
27
- /**
28
- * @param {String} path
29
- * @return {Buffer} Hash of the file.
30
- */
31
- exports.hashFile = async function (path) {
32
- return new Promise((resolve, reject) => {
33
- const sha256 = crypto.createHash('sha256');
34
- fs.createReadStream(path)
35
- .on('close', () => resolve(sha256.digest()))
36
- .on('data', data => sha256.update(data))
37
- .on('error', reject);
38
- });
39
- }
40
-
41
- /**
42
- * @type {NodeJS.Platform[]}
43
- */
44
- exports.platforms = [
45
- 'darwin',
46
- 'linux',
47
- 'win32',
48
- ];
49
-
50
- /**
51
- * Return both the relative folder and the ffmpeg shared library name.
52
- *
53
- * @param {NodeJS.Platform} [platform]
54
- * @return {File}
55
- */
56
- exports.libffmpegLocation = function (platform = process.platform) {
57
- switch (platform) {
58
- case 'darwin':
59
- return {
60
- name: 'libffmpeg.dylib',
61
- folder: 'Electron.app/Contents/Frameworks/Electron Framework.framework/Libraries/',
62
- };
63
- case 'win32':
64
- return {
65
- name: 'ffmpeg.dll',
66
- };
67
- case 'linux':
68
- return {
69
- name: 'libffmpeg.so',
70
- };
71
- default:
72
- throw new Error(`${platform} is not supported`);
73
- }
74
- };
75
-
76
- /**
77
- * Compute the relative ffmpeg shared library path from the Electron distribution root.
78
- *
79
- * @param {libffmpegPlatformOptions} [options]
80
- * @return {String}
81
- */
82
- exports.libffmpegRelativePath = function ({ platform } = {}) {
83
- const libffmpeg = exports.libffmpegLocation(platform);
84
- return path.join(libffmpeg.folder || '', libffmpeg.name);
85
- };
86
-
87
- /**
88
- * Compute the absolute ffmpeg shared library path.
89
- *
90
- * @param {libffmpegDistributionOptions} [options]
91
- * @return {String}
92
- */
93
- exports.libffmpegAbsolutePath = function ({ platform, electronDist } = {}) {
94
- if (!electronDist) electronDist = path.resolve(require.resolve('electron/index.js'), '..', 'dist');
95
- return path.join(electronDist, exports.libffmpegRelativePath({ platform }));
96
- };
97
-
98
- /**
99
- * Return the list of codecs for the given ffmpeg shared library.
100
- *
101
- * @param {libffmpegDistributionOptions} [options]
102
- * @return {String}
103
- */
104
- exports.libffmpegCodecs = function (absolutePath) {
105
- return ffmpeg.codecs(absolutePath);
106
- };
107
-
108
- /**
109
- * @typedef {Object} File
110
- * @property {String} name
111
- * @property {String} [folder]
112
- */
113
-
114
- /**
115
- * @typedef {Object} Codec
116
- * @property {Number} id
117
- * @property {String} name
118
- * @property {String} longName
119
- */
120
-
121
- /**
122
- * @typedef {Object} libffmpegPlatformOptions
123
- * @property {NodeJS.Platform} [platform]
124
- */
125
-
126
- /**
127
- * @typedef {Object} libffmpegDistributionOptions
128
- * @property {NodeJS.Platform} [platform]
129
- * @property {String} [electronDist]
130
- */
@@ -1,127 +0,0 @@
1
- #!/usr/bin/env node
2
- /********************************************************************************
3
- * Copyright (C) 2019 Ericsson and others.
4
- *
5
- * This program and the accompanying materials are made available under the
6
- * terms of the Eclipse Public License v. 2.0 which is available at
7
- * http://www.eclipse.org/legal/epl-2.0.
8
- *
9
- * This Source Code may also be made available under the following Secondary
10
- * Licenses when the conditions for such availability set forth in the Eclipse
11
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- * with the GNU Classpath Exception which is available at
13
- * https://www.gnu.org/software/classpath/license.html.
14
- *
15
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- ********************************************************************************/
17
- 'use-strict'
18
-
19
- // @ts-check
20
-
21
- const electronGet = require('@electron/get');
22
- const unzipper = require('unzipper');
23
- const yargs = require('yargs');
24
- const path = require('path');
25
- const fs = require('fs');
26
-
27
- const { hashFile, platforms, libffmpegLocation } = require('./electron-ffmpeg-lib')
28
-
29
- const downloadCache = path.resolve(__dirname, 'download');
30
- if (!fs.existsSync(downloadCache)) {
31
- fs.mkdirSync(downloadCache);
32
- }
33
-
34
- async function main() {
35
- const options = yargs
36
- .option('electronVersion', {
37
- alias: ['v'],
38
- description: 'Electron version for which to pull the "clean" ffmpeg library.',
39
- })
40
- .option('absolutePath', {
41
- alias: ['a'],
42
- description: 'Absolute path to the ffmpeg shared library.',
43
- })
44
- .option('electronDist', {
45
- alias: ['d'],
46
- description: 'Electron distribution location.',
47
- })
48
- .option('platform', {
49
- alias: ['p'],
50
- description: 'Dictates where the library is located within the Electron distribution.',
51
- choices: platforms,
52
- })
53
- .help().alias('h', 'help')
54
- .exitProcess(false)
55
- .argv;
56
-
57
- if (options.help) {
58
- return; // help is being displayed.
59
- }
60
-
61
- let shouldDownload = true;
62
- let shouldReplace = true;
63
-
64
- const {
65
- name: libffmpegFileName,
66
- folder: libffmpegFolder = '',
67
- } = libffmpegLocation(options['platform']);
68
-
69
- const electronDist = options['electronDist'] || path.resolve(require.resolve('electron/index.js'), '..', 'dist');
70
- const libffmpegDistPath = options['absolutePath'] || path.resolve(electronDist, libffmpegFolder, libffmpegFileName);
71
- const libffmpegCachedPath = path.resolve(downloadCache, libffmpegFileName);
72
-
73
- if (fs.existsSync(libffmpegCachedPath)) {
74
- shouldDownload = false; // If the file is already cached, do not download.
75
- console.info('Found cached ffmpeg library.');
76
- const [cacheHash, distHash] = await Promise.all([
77
- hashFile(libffmpegCachedPath),
78
- hashFile(libffmpegDistPath),
79
- ])
80
- if (cacheHash.equals(distHash)) {
81
- shouldReplace = false; // If files are already the same, do not replace.
82
- console.info('Hashes are equal, not replacing the ffmpeg library.');
83
- }
84
- }
85
-
86
- if (shouldDownload) {
87
- let electronVersion = options['electronVersion'];
88
- if (!electronVersion) {
89
- const electronVersionFilePath = path.resolve(electronDist, 'version');
90
- electronVersion = fs.readFileSync(electronVersionFilePath, {
91
- encoding: 'utf8'
92
- }).trim();
93
- }
94
-
95
- const libffmpegZipPath = await electronGet.downloadArtifact({
96
- version: electronVersion,
97
- artifactName: 'ffmpeg'
98
- });
99
-
100
- const libffmpegZip = await unzipper.Open.file(libffmpegZipPath);
101
- file = libffmpegZip.files.find(file => file.path.endsWith(libffmpegFileName));
102
- if (!file) {
103
- throw new Error(`Archive did not contain "${libffmpegFileName}".`);
104
- }
105
-
106
- // Extract file to cache.
107
- await new Promise((resolve, reject) => {
108
- file.stream()
109
- .pipe(fs.createWriteStream(libffmpegCachedPath))
110
- .on('finish', resolve)
111
- .on('error', reject);
112
- });
113
-
114
- console.info(`Downloaded ffmpeg shared library { version: "${electronVersion}", dist: "${electronDist}" }.`);
115
- }
116
-
117
- if (shouldReplace) {
118
- fs.copyFileSync(libffmpegCachedPath, libffmpegDistPath);
119
- console.info(`Successfully replaced "${libffmpegDistPath}".`);
120
- }
121
-
122
- }
123
-
124
- main().catch(error => {
125
- console.error(error);
126
- process.exit(1);
127
- });
package/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import Electron = require('electron');
2
- export = Electron;
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('electron');
@@ -1,29 +0,0 @@
1
- {
2
- 'targets': [{
3
- 'defines': ['NAPI_VERSION=2'],
4
- 'target_name': 'ffmpeg',
5
- 'sources': [
6
- 'src/ffmpeg.c',
7
- ],
8
- 'conditions': [
9
- ['OS=="linux"', {
10
- 'sources': [
11
- 'src/linux-ffmpeg.c',
12
- ],
13
- 'libraries': [
14
- '-ldl',
15
- ]
16
- }],
17
- ['OS=="mac"', {
18
- 'sources': [
19
- 'src/mac-ffmpeg.c',
20
- ]
21
- }],
22
- ['OS=="win"', {
23
- 'sources': [
24
- 'src/win-ffmpeg.c',
25
- ]
26
- }],
27
- ],
28
- }],
29
- }
@@ -1,146 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (C) 2019 Ericsson and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the Eclipse Public License v. 2.0 which is available at
6
- * http://www.eclipse.org/legal/epl-2.0.
7
- *
8
- * This Source Code may also be made available under the following Secondary
9
- * Licenses when the conditions for such availability set forth in the Eclipse
10
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- * with the GNU Classpath Exception which is available at
12
- * https://www.gnu.org/software/classpath/license.html.
13
- *
14
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
-
17
- /**
18
- * https://nodejs.org/docs/latest-v10.x/api/n-api.html#n_api_n_api
19
- */
20
- #include <node_api.h>
21
-
22
- #include <string.h>
23
-
24
- #include "ffmpeg.h"
25
-
26
- /**
27
- * Return the list of codecs registered in the FFMPEG library.
28
- */
29
- napi_value codecs(napi_env env, napi_callback_info info)
30
- {
31
- // We will reuse this `status` for all napi calls.
32
- napi_status status;
33
- char *error = NULL;
34
-
35
- // Get arguments.
36
- size_t argc = 1;
37
- napi_value argv[1];
38
- status = napi_get_cb_info(env, info, &argc, argv, NULL, NULL);
39
- if (status != napi_ok || argc < 1)
40
- {
41
- error = "invalid arguments";
42
- goto error;
43
- }
44
-
45
- // Get first argument as string.
46
- char path[2048];
47
- status = napi_get_value_string_utf8(env, argv[0], path, 2048, NULL);
48
- if (status != napi_ok)
49
- {
50
- error = "invalid string argument";
51
- goto error;
52
- }
53
-
54
- // Load ffmpeg based on the provided path.
55
- struct FFMPEG_Library ffmpeg = NULL_FFMPEG_LIBRARY;
56
- char *load_error = load_ffmpeg_library(&ffmpeg, path);
57
- if (load_error != NULL)
58
- {
59
- error = load_error;
60
- goto error;
61
- }
62
-
63
- // Create the JavaScript list that will be returned.
64
- napi_value codecs;
65
- status = napi_create_array(env, &codecs);
66
- if (status != napi_ok)
67
- {
68
- error = "napi_create_array fail";
69
- goto error;
70
- }
71
-
72
- // Iterate over the codec descriptions.
73
- // It includes descriptions for codecs that may not be present in the library.
74
- struct AVCodecDescriptor *descriptor = ffmpeg.avcodec_descriptor_next(NULL);
75
- while (descriptor != NULL)
76
- {
77
- // Try to fetch the codec being described, returns null on missing codecs.
78
- struct AVCodec *decoder = ffmpeg.avcodec_find_decoder(descriptor->id);
79
- if (decoder != NULL)
80
- {
81
- // Create the codec object and assign the properties.
82
- napi_value object, value;
83
- napi_create_object(env, &object);
84
-
85
- // id: number
86
- napi_create_int32(env, decoder->id, &value);
87
- napi_set_named_property(env, object, "id", value);
88
-
89
- // name: string
90
- napi_create_string_utf8(env, decoder->name, strlen(decoder->name), &value);
91
- napi_set_named_property(env, object, "name", value);
92
-
93
- // longName: string
94
- napi_create_string_utf8(env, decoder->long_name, strlen(decoder->long_name), &value);
95
- napi_set_named_property(env, object, "longName", value);
96
-
97
- // Pushing into a JS array requires calling the JS method for that.
98
- napi_value push_fn;
99
- napi_get_named_property(env, codecs, "push", &push_fn);
100
- napi_call_function(env, codecs, push_fn, 1, (napi_value[]){object}, NULL);
101
- }
102
- descriptor = ffmpeg.avcodec_descriptor_next(descriptor);
103
- }
104
-
105
- // Free the ffmpeg library.
106
- char *unload_error = unload_ffmpeg_library(&ffmpeg);
107
- if (unload_error != NULL)
108
- {
109
- error = unload_error;
110
- goto error;
111
- }
112
-
113
- return codecs;
114
-
115
- error:
116
- if (error != NULL)
117
- {
118
- napi_throw_error(env, NULL, error);
119
- }
120
- return NULL;
121
- }
122
-
123
- /**
124
- * https://nodejs.org/docs/latest-v10.x/api/n-api.html#n_api_module_registration
125
- */
126
- napi_value initialize(napi_env env, napi_value exports)
127
- {
128
- napi_status status;
129
- napi_value function_codecs;
130
-
131
- status = napi_create_function(env, NULL, 0, codecs, NULL, &function_codecs);
132
- if (status != napi_ok)
133
- {
134
- return NULL;
135
- }
136
-
137
- status = napi_set_named_property(env, exports, "codecs", function_codecs);
138
- if (status != napi_ok)
139
- {
140
- return NULL;
141
- }
142
-
143
- return exports;
144
- }
145
-
146
- NAPI_MODULE(NODE_GYP_MODULE_NAME, initialize);
@@ -1,80 +0,0 @@
1
- #ifndef FFMPEG_H
2
- #define FFMPEG_H
3
- /**
4
- * THIS FILE REDEFINES DATA AS RETURNED BY THE FFMPEG LIBRARY.
5
- * HEADER FILES ARE NOT DISTRIBUTED IN OUR SETUP, HENCE THIS.
6
- */
7
-
8
- /**
9
- * https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavutil/avutil.h#L193-L201
10
- */
11
- enum AVMediaType
12
- {
13
- _UNKNOWN_DATA_AVMediaType = -1,
14
- };
15
-
16
- /**
17
- * https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L191-L653
18
- */
19
- enum AVCodecID
20
- {
21
- __UNKNOWN_DATA_AVCodecID = 0,
22
- };
23
-
24
- /**
25
- * https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L3611-L3721
26
- */
27
- struct AVCodec
28
- {
29
- const char *name, *long_name;
30
- enum AVMediaType type;
31
- enum AVCodecID id;
32
- };
33
-
34
- /**
35
- * https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L660-L688
36
- */
37
- struct AVCodecDescriptor
38
- {
39
- enum AVCodecID id;
40
- enum AVMediaType type;
41
- const char *name, *long_name;
42
- };
43
-
44
- /**
45
- * Wrapper around the ffmpeg library that must be loaded at runtime.
46
- */
47
- struct FFMPEG_Library
48
- {
49
- void *handle;
50
-
51
- /**
52
- * https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L6228
53
- *
54
- * We use AVCodecDescriptor because it is the only structure that we can
55
- * query on all platforms. Windows' ffmpeg.dll does not export a
56
- * `av_codec_next` function, only `avcodec_descriptor_next`.
57
- * Also it seems that this "descriptor" concept is the recommended API.
58
- */
59
- struct AVCodecDescriptor *(*avcodec_descriptor_next)(const struct AVCodecDescriptor *);
60
-
61
- /**
62
- * https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L4646
63
- */
64
- struct AVCodec *(*avcodec_find_decoder)(enum AVCodecID);
65
- };
66
-
67
- #define NULL_FFMPEG_LIBRARY \
68
- (struct FFMPEG_Library) { NULL, NULL, NULL }
69
-
70
- /**
71
- * Loader that will inject the loaded functions into a FFMPEG_Library structure.
72
- */
73
- char *load_ffmpeg_library(struct FFMPEG_Library *library, char *library_path);
74
-
75
- /**
76
- * Free library.
77
- */
78
- char *unload_ffmpeg_library(struct FFMPEG_Library *library);
79
-
80
- #endif // FFMPEG_H guard
@@ -1,68 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (C) 2019 Ericsson and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the Eclipse Public License v. 2.0 which is available at
6
- * http://www.eclipse.org/legal/epl-2.0.
7
- *
8
- * This Source Code may also be made available under the following Secondary
9
- * Licenses when the conditions for such availability set forth in the Eclipse
10
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- * with the GNU Classpath Exception which is available at
12
- * https://www.gnu.org/software/classpath/license.html.
13
- *
14
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
-
17
- #ifndef LINUX_FFMPEG
18
- #define LINUX_FFMPEG
19
-
20
- #include <stdlib.h>
21
- #include <dlfcn.h>
22
-
23
- #include "ffmpeg.h"
24
-
25
- char *load_ffmpeg_library(struct FFMPEG_Library *library, char *library_path)
26
- {
27
- void *handle = dlopen(library_path, RTLD_NOW);
28
- char *error = dlerror();
29
- if (error != NULL)
30
- {
31
- goto error;
32
- }
33
-
34
- struct AVCodecDescriptor *(*avcodec_descriptor_next)(const struct AVCodecDescriptor *) = dlsym(handle, "avcodec_descriptor_next");
35
- error = dlerror();
36
- if (error != NULL)
37
- {
38
- goto error;
39
- }
40
-
41
- struct AVCodec *(*avcodec_find_decoder)(enum AVCodecID) = dlsym(handle, "avcodec_find_decoder");
42
- error = dlerror();
43
- if (error != NULL)
44
- {
45
- goto error;
46
- }
47
-
48
- library->handle = handle;
49
- library->avcodec_descriptor_next = avcodec_descriptor_next;
50
- library->avcodec_find_decoder = avcodec_find_decoder;
51
- return NULL;
52
-
53
- error:
54
- if (handle != NULL)
55
- {
56
- dlclose(handle);
57
- }
58
- return error;
59
- }
60
-
61
- char *unload_ffmpeg_library(struct FFMPEG_Library *library)
62
- {
63
- dlclose(library->handle);
64
- *library = NULL_FFMPEG_LIBRARY;
65
- return dlerror();
66
- }
67
-
68
- #endif // LINUX_FFMPEG guard
@@ -1,26 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (C) 2019 Ericsson and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the Eclipse Public License v. 2.0 which is available at
6
- * http://www.eclipse.org/legal/epl-2.0.
7
- *
8
- * This Source Code may also be made available under the following Secondary
9
- * Licenses when the conditions for such availability set forth in the Eclipse
10
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- * with the GNU Classpath Exception which is available at
12
- * https://www.gnu.org/software/classpath/license.html.
13
- *
14
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
-
17
- #ifndef MAC_FFMPEG
18
- #define MAC_FFMPEG
19
-
20
- /**
21
- * Mac seems to use the same libraries as Linux.
22
- * Difference is that the compiler doesn't need to be told to use `-ldl`.
23
- */
24
- #include "./linux-ffmpeg.c"
25
-
26
- #endif // MAC_FFMPEG guard
@@ -1,77 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (C) 2019 Ericsson and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the Eclipse Public License v. 2.0 which is available at
6
- * http://www.eclipse.org/legal/epl-2.0.
7
- *
8
- * This Source Code may also be made available under the following Secondary
9
- * Licenses when the conditions for such availability set forth in the Eclipse
10
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- * with the GNU Classpath Exception which is available at
12
- * https://www.gnu.org/software/classpath/license.html.
13
- *
14
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
- #ifndef WIN_FFMPEG
17
- #define WIN_FFMPEG
18
-
19
- #include <windows.h>
20
-
21
- #include "ffmpeg.h"
22
-
23
- static char *error_library_not_found = "shared library not found";
24
- static char *error_function_not_found = "function not found in shared library";
25
- static char *error_cannot_free_library = "cannot free shared library";
26
-
27
- char *load_ffmpeg_library(struct FFMPEG_Library *library, char *library_path)
28
- {
29
- char *error = NULL;
30
-
31
- HMODULE handle = LoadLibrary(library_path);
32
- if (!handle)
33
- {
34
- error = error_library_not_found;
35
- goto error;
36
- }
37
-
38
- struct AVCodecDescriptor *(*av_codec_next)(const struct AVCodecDescriptor *) = (struct AVCodecDescriptor * (*)(const struct AVCodecDescriptor *))
39
- GetProcAddress(handle, "avcodec_descriptor_next");
40
- if (!av_codec_next)
41
- {
42
- error = error_function_not_found;
43
- goto error;
44
- }
45
-
46
- struct AVCodec *(*avcodec_find_decoder)(enum AVCodecID) = (struct AVCodec * (*)(enum AVCodecID))
47
- GetProcAddress(handle, "avcodec_find_decoder");
48
- if (!avcodec_find_decoder)
49
- {
50
- error = error_function_not_found;
51
- goto error;
52
- }
53
-
54
- library->handle = handle;
55
- library->avcodec_descriptor_next = av_codec_next;
56
- library->avcodec_find_decoder = avcodec_find_decoder;
57
- return NULL;
58
-
59
- error:
60
- if (handle)
61
- {
62
- FreeLibrary(handle);
63
- }
64
- return error;
65
- }
66
-
67
- char *unload_ffmpeg_library(struct FFMPEG_Library *library)
68
- {
69
- if (library->handle && FreeLibrary(library->handle))
70
- {
71
- *library = NULL_FFMPEG_LIBRARY;
72
- return NULL;
73
- }
74
- return error_cannot_free_library;
75
- }
76
-
77
- #endif // WIN_FFMPEG guard
@@ -1 +0,0 @@
1
- export * from 'native-keymap'
package/native-keymap.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('native-keymap');
package/node-gyp-cli.js DELETED
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env node
2
- /********************************************************************************
3
- * Copyright (C) 2019 Ericsson and others.
4
- *
5
- * This program and the accompanying materials are made available under the
6
- * terms of the Eclipse Public License v. 2.0 which is available at
7
- * http://www.eclipse.org/legal/epl-2.0.
8
- *
9
- * This Source Code may also be made available under the following Secondary
10
- * Licenses when the conditions for such availability set forth in the Eclipse
11
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- * with the GNU Classpath Exception which is available at
13
- * https://www.gnu.org/software/classpath/license.html.
14
- *
15
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- ********************************************************************************/
17
-
18
- require('node-gyp/bin/node-gyp.js')
@@ -1,85 +0,0 @@
1
- #!/usr/bin/env node
2
- /********************************************************************************
3
- * Copyright (C) 2019 Ericsson and others.
4
- *
5
- * This program and the accompanying materials are made available under the
6
- * terms of the Eclipse Public License v. 2.0 which is available at
7
- * http://www.eclipse.org/legal/epl-2.0.
8
- *
9
- * This Source Code may also be made available under the following Secondary
10
- * Licenses when the conditions for such availability set forth in the Eclipse
11
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- * with the GNU Classpath Exception which is available at
13
- * https://www.gnu.org/software/classpath/license.html.
14
- *
15
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- ********************************************************************************/
17
- 'use strict'
18
-
19
- // @ts-check
20
-
21
- // const path = require('path');
22
- const cp = require('child_process');
23
- const fs = require('fs');
24
-
25
- /**
26
- * @param {String} script
27
- * @param {String[]} args
28
- * @param {import('child_process').ForkOptions} options
29
- * @param {Function} [callback]
30
- */
31
- async function fork(script, args = [], options = {}, callback) {
32
- return new Promise((resolve, reject) => {
33
- const subprocess = cp.fork(script, args, options);
34
- subprocess.once('error', reject);
35
- subprocess.once('close', (code, signal) => {
36
- if (signal || code) reject(new Error(`"${script}" exited with ${signal || code}`));
37
- else resolve();
38
- });
39
- // pid 0 is unlikely: pid will be > 0, or null/undefined on error.
40
- if (subprocess.pid && callback) {
41
- callback(subprocess);
42
- }
43
- })
44
- }
45
-
46
- /**
47
- * @param {String} type
48
- * @param {String} message
49
- * @return {String}
50
- */
51
- function format(type, message) {
52
- return `(${new Date().toUTCString()}) ${type}: ${message}`;
53
- }
54
-
55
- /**
56
- * @param {import('child_process').ChildProcess} subprocess
57
- * @param {import('stream').Writable} stream
58
- */
59
- async function writeToStream(subprocess, stream) {
60
- subprocess.stdout.on('data', data => {
61
- console.info(data.toString().trimRight());
62
- stream.write(format('info', data));
63
- });
64
- subprocess.stderr.on('data', data => {
65
- console.error(data.toString().trimRight());
66
- stream.write(format('error', data))
67
- });
68
- }
69
-
70
- async function main() {
71
- await fork('../node-gyp-cli.js', ['rebuild'], { cwd: 'native' });
72
- if (!process.env.THEIA_ELECTRON_SKIP_REPLACE_FFMPEG) {
73
- const log = fs.createWriteStream('post-install.log', { encoding: 'utf8' });
74
- await new Promise(resolve => log.once('open', () => resolve()));
75
- await fork('electron-replace-ffmpeg.js', [], { stdio: [0, 'pipe', 'pipe', 'ipc'] },
76
- subprocess => writeToStream(subprocess, log));
77
- await fork('electron-codecs-test.js', [], { stdio: [0, 'pipe', 'pipe', 'ipc'] },
78
- subprocess => writeToStream(subprocess, log));
79
- }
80
- }
81
-
82
- main().catch(error => {
83
- console.error(error);
84
- process.exit(error.code || 127);
85
- })