node-libcec 1.0.1 → 1.0.3

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.md CHANGED
@@ -28,7 +28,7 @@ npm install node-libcec
28
28
  ## Quick Start
29
29
 
30
30
  ```javascript
31
- const { CECAdapter, LogicalAddress, DeviceType } = require('node-libcec');
31
+ import { CECAdapter, LogicalAddress, DeviceType } from 'node-libcec';
32
32
 
33
33
  // Create adapter
34
34
  const cec = new CECAdapter({
@@ -164,7 +164,7 @@ cec.on('configurationChanged', (config) => { }); // Config changes
164
164
  ### Constants
165
165
 
166
166
  ```javascript
167
- const {
167
+ import {
168
168
  LogicalAddress, // TV, RECORDING_DEVICE_1, PLAYBACK_DEVICE_1, etc.
169
169
  DeviceType, // TV, RECORDING_DEVICE, PLAYBACK_DEVICE, etc.
170
170
  PowerStatus, // ON, STANDBY, IN_TRANSITION_*, UNKNOWN
@@ -174,7 +174,7 @@ const {
174
174
  DisplayControl, // DISPLAY_FOR_DEFAULT_TIME, DISPLAY_UNTIL_CLEARED, etc.
175
175
  Version, // V1_2, V1_3, V1_4, V2_0, etc.
176
176
  AlertType // SERVICE_DEVICE, CONNECTION_LOST, etc.
177
- } = require('node-libcec');
177
+ } from 'node-libcec';
178
178
  ```
179
179
 
180
180
  ## Examples
package/lib/constants.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * CEC Logical Addresses
3
3
  */
4
- const LogicalAddress = {
4
+ export const LogicalAddress = {
5
5
  TV: 0,
6
6
  RECORDING_DEVICE_1: 1,
7
7
  RECORDING_DEVICE_2: 2,
@@ -24,7 +24,7 @@ const LogicalAddress = {
24
24
  /**
25
25
  * CEC Device Types
26
26
  */
27
- const DeviceType = {
27
+ export const DeviceType = {
28
28
  TV: 0,
29
29
  RECORDING_DEVICE: 1,
30
30
  RESERVED: 2,
@@ -36,7 +36,7 @@ const DeviceType = {
36
36
  /**
37
37
  * CEC Power Status
38
38
  */
39
- const PowerStatus = {
39
+ export const PowerStatus = {
40
40
  ON: 0x00,
41
41
  STANDBY: 0x01,
42
42
  IN_TRANSITION_STANDBY_TO_ON: 0x02,
@@ -47,7 +47,7 @@ const PowerStatus = {
47
47
  /**
48
48
  * CEC Opcodes
49
49
  */
50
- const Opcode = {
50
+ export const Opcode = {
51
51
  ACTIVE_SOURCE: 0x82,
52
52
  IMAGE_VIEW_ON: 0x04,
53
53
  TEXT_VIEW_ON: 0x0D,
@@ -125,7 +125,7 @@ const Opcode = {
125
125
  /**
126
126
  * CEC User Control Codes (Remote buttons)
127
127
  */
128
- const UserControlCode = {
128
+ export const UserControlCode = {
129
129
  SELECT: 0x00,
130
130
  UP: 0x01,
131
131
  DOWN: 0x02,
@@ -219,7 +219,7 @@ const UserControlCode = {
219
219
  /**
220
220
  * CEC Log Level
221
221
  */
222
- const LogLevel = {
222
+ export const LogLevel = {
223
223
  ERROR: 1,
224
224
  WARNING: 2,
225
225
  NOTICE: 4,
@@ -231,7 +231,7 @@ const LogLevel = {
231
231
  /**
232
232
  * CEC Display Control (for OSD strings)
233
233
  */
234
- const DisplayControl = {
234
+ export const DisplayControl = {
235
235
  DISPLAY_FOR_DEFAULT_TIME: 0x00,
236
236
  DISPLAY_UNTIL_CLEARED: 0x40,
237
237
  CLEAR_PREVIOUS_MESSAGE: 0x80,
@@ -241,7 +241,7 @@ const DisplayControl = {
241
241
  /**
242
242
  * CEC Version
243
243
  */
244
- const Version = {
244
+ export const Version = {
245
245
  UNKNOWN: 0x00,
246
246
  V1_2: 0x01,
247
247
  V1_2A: 0x02,
@@ -254,7 +254,7 @@ const Version = {
254
254
  /**
255
255
  * Alert Types
256
256
  */
257
- const AlertType = {
257
+ export const AlertType = {
258
258
  SERVICE_DEVICE: 1,
259
259
  CONNECTION_LOST: 2,
260
260
  PERMISSION_ERROR: 3,
@@ -262,14 +262,3 @@ const AlertType = {
262
262
  PHYSICAL_ADDRESS_ERROR: 5
263
263
  };
264
264
 
265
- module.exports = {
266
- LogicalAddress,
267
- DeviceType,
268
- PowerStatus,
269
- Opcode,
270
- UserControlCode,
271
- LogLevel,
272
- DisplayControl,
273
- Version,
274
- AlertType
275
- };
package/lib/index.js CHANGED
@@ -1,18 +1,24 @@
1
- const EventEmitter = require('events');
1
+ import { EventEmitter } from 'events';
2
+ import { createRequire } from 'module';
3
+ import { fileURLToPath } from 'url';
4
+ import { dirname, join } from 'path';
5
+
6
+ const require = createRequire(import.meta.url);
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
2
8
 
3
9
  // Load native addon
4
10
  let native;
5
11
  try {
6
- native = require('../build/Release/cec.node');
12
+ native = require(join(__dirname, '../build/Release/cec.node'));
7
13
  } catch (e) {
8
14
  try {
9
- native = require('../build/Debug/cec.node');
15
+ native = require(join(__dirname, '../build/Debug/cec.node'));
10
16
  } catch (e2) {
11
17
  throw new Error('Failed to load native cec module. Did you run npm run build?');
12
18
  }
13
19
  }
14
20
 
15
- const constants = require('./constants');
21
+ import * as constants from './constants.js';
16
22
 
17
23
  /**
18
24
  * CEC Adapter class - provides high-level interface to libcec
@@ -427,7 +433,5 @@ class CECAdapter extends EventEmitter {
427
433
  }
428
434
 
429
435
  // Export everything
430
- module.exports = {
431
- CECAdapter,
432
- ...constants
433
- };
436
+ export { CECAdapter };
437
+ export * from './constants.js';
package/package.json CHANGED
@@ -1,13 +1,20 @@
1
1
  {
2
2
  "name": "node-libcec",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Node.js bindings for libcec - control CEC devices over HDMI",
5
+ "type": "module",
5
6
  "main": "lib/index.js",
7
+ "exports": {
8
+ ".": "./lib/index.js"
9
+ },
6
10
  "scripts": {
7
11
  "build": "node-gyp rebuild",
8
12
  "clean": "node-gyp clean",
9
13
  "prepare": "npm run build",
10
- "test": "node --test test/"
14
+ "test": "node --test test/",
15
+ "release:patch": "npm version patch && npm publish",
16
+ "release:minor": "npm version minor && npm publish",
17
+ "release:major": "npm version major && npm publish"
11
18
  },
12
19
  "keywords": [
13
20
  "cec",
@@ -43,4 +50,4 @@
43
50
  "node-gyp": "^10.0.0"
44
51
  },
45
52
  "gypfile": true
46
- }
53
+ }
@@ -158,7 +158,7 @@ void CECCallbackHandler::LogMessageCallback(void* cbParam, const cec_log_message
158
158
  message->time
159
159
  };
160
160
 
161
- handler->logMessageTsfn_.BlockingCall(data, [](Napi::Env env, Napi::Function jsCallback, LogMessageData* data) {
161
+ handler->logMessageTsfn_.NonBlockingCall(data, [](Napi::Env env, Napi::Function jsCallback, LogMessageData* data) {
162
162
  Napi::Object obj = Napi::Object::New(env);
163
163
  obj.Set("message", Napi::String::New(env, data->message));
164
164
  obj.Set("level", Napi::Number::New(env, data->level));
@@ -183,7 +183,7 @@ void CECCallbackHandler::KeyPressCallback(void* cbParam, const cec_keypress* key
183
183
  static_cast<int>(key->duration)
184
184
  };
185
185
 
186
- handler->keyPressTsfn_.BlockingCall(data, [](Napi::Env env, Napi::Function jsCallback, KeyPressData* data) {
186
+ handler->keyPressTsfn_.NonBlockingCall(data, [](Napi::Env env, Napi::Function jsCallback, KeyPressData* data) {
187
187
  Napi::Object obj = Napi::Object::New(env);
188
188
  obj.Set("keycode", Napi::Number::New(env, data->keycode));
189
189
  obj.Set("duration", Napi::Number::New(env, data->duration));
@@ -217,7 +217,7 @@ void CECCallbackHandler::CommandReceivedCallback(void* cbParam, const cec_comman
217
217
  std::vector<uint8_t>(command->parameters.data, command->parameters.data + command->parameters.size)
218
218
  };
219
219
 
220
- handler->commandTsfn_.BlockingCall(data, [](Napi::Env env, Napi::Function jsCallback, CommandData* data) {
220
+ handler->commandTsfn_.NonBlockingCall(data, [](Napi::Env env, Napi::Function jsCallback, CommandData* data) {
221
221
  Napi::Object obj = Napi::Object::New(env);
222
222
  obj.Set("initiator", Napi::Number::New(env, data->initiator));
223
223
  obj.Set("destination", Napi::Number::New(env, data->destination));
@@ -256,7 +256,7 @@ void CECCallbackHandler::ConfigurationChangedCallback(void* cbParam, const libce
256
256
  config->iHDMIPort
257
257
  };
258
258
 
259
- handler->configChangedTsfn_.BlockingCall(data, [](Napi::Env env, Napi::Function jsCallback, ConfigChangedData* data) {
259
+ handler->configChangedTsfn_.NonBlockingCall(data, [](Napi::Env env, Napi::Function jsCallback, ConfigChangedData* data) {
260
260
  Napi::Object obj = Napi::Object::New(env);
261
261
  obj.Set("deviceName", Napi::String::New(env, data->deviceName));
262
262
  obj.Set("physicalAddress", Napi::Number::New(env, data->physicalAddress));
@@ -280,7 +280,7 @@ void CECCallbackHandler::AlertCallback(void* cbParam, const libcec_alert type, c
280
280
  static_cast<int>(type)
281
281
  };
282
282
 
283
- handler->alertTsfn_.BlockingCall(data, [](Napi::Env env, Napi::Function jsCallback, AlertData* data) {
283
+ handler->alertTsfn_.NonBlockingCall(data, [](Napi::Env env, Napi::Function jsCallback, AlertData* data) {
284
284
  Napi::Object obj = Napi::Object::New(env);
285
285
  obj.Set("type", Napi::Number::New(env, data->alertType));
286
286
  jsCallback.Call({obj});
@@ -303,7 +303,7 @@ void CECCallbackHandler::SourceActivatedCallback(void* cbParam, const cec_logica
303
303
  activated != 0
304
304
  };
305
305
 
306
- handler->sourceActivatedTsfn_.BlockingCall(data, [](Napi::Env env, Napi::Function jsCallback, SourceActivatedData* data) {
306
+ handler->sourceActivatedTsfn_.NonBlockingCall(data, [](Napi::Env env, Napi::Function jsCallback, SourceActivatedData* data) {
307
307
  Napi::Object obj = Napi::Object::New(env);
308
308
  obj.Set("logicalAddress", Napi::Number::New(env, data->logicalAddress));
309
309
  obj.Set("activated", Napi::Boolean::New(env, data->activated));