Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

elemental-live-client

Package Overview
Dependencies
Maintainers
4
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elemental-live-client - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

37

lib/device.js
const resource = require('./resource');
const queryString = (object) => {
const parts = [];
for (const key in object) {
if (Reflect.apply(Object.prototype.hasOwnProperty, object, [key])) {
parts.push(`${key}=${object[key]}`);
}
}
return parts.join('&');
};
class Device extends resource.Resource {

@@ -44,30 +32,7 @@ constructor(elementalClient) {

return this.elementalClient.sendRequest('POST', `/api/devices/${opts.id}/preview`, null, data).
return this.elementalClient.sendRequest('POST', `/devices/${opts.id}/preview`, null, data).
then((respData) => respData.preview_images.preview_image);
}
generatePreview(opts) {
if (!opts.id) {
throw new Error('missing device id');
}
if (!opts.sourceType) {
throw new Error('missing source type');
}
const inputData = {
'input_key': 0,
'live_event[inputs_attributes][0][source_type]': opts.sourceType,
'live_event[inputs_attributes][0][device_input_attributes][sdi_settings_attributes][input_format]': 'Auto',
'live_event[inputs_attributes][0][device_input_attributes][device_id]': opts.id,
};
const body = queryString(inputData);
const headers = {
'Accept': '*/*',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
};
return this.elementalClient.sendRequest('POST', '/inputs/generate_preview', null, body, headers);
}
}
module.exports = {Device};

19

lib/live-event.js

@@ -6,3 +6,2 @@ const resource = require('./resource');

super(elementalClient, 'live_events');
this.version = elementalClient.version ? `${elementalClient.version}/` : '';

@@ -12,3 +11,3 @@ // these operations are mapped to methods named <operation>Event, that

['start', 'stop', 'cancel', 'archive', 'reset'].forEach((opName) => {
this[`${opName}Event`] = (eventId) => this.elementalClient.sendRequest('POST', `/api/live_events/${eventId}/${opName}`);
this[`${opName}Event`] = (eventId) => this.elementalClient.sendRequest('POST', `/live_events/${eventId}/${opName}`);
});

@@ -20,27 +19,27 @@ }

eventStatus(eventId, headers = null) {
return this.elementalClient.sendRequest('GET', `/api/${this.version}live_events/${eventId}/status`, null, null, headers);
return this.elementalClient.sendRequest('GET', `/live_events/${eventId}/status`, null, null, headers);
}
listInputs(eventId) {
return this.elementalClient.sendRequest('GET', `/api/${this.version}live_events/${eventId}/inputs`);
return this.elementalClient.sendRequest('GET', `/live_events/${eventId}/inputs`);
}
muteEvent(eventId) {
return this.elementalClient.sendRequest('POST', `/api/${this.version}live_events/${eventId}/mute_audio`);
return this.elementalClient.sendRequest('POST', `/live_events/${eventId}/mute_audio`);
}
unmuteEvent(eventId) {
return this.elementalClient.sendRequest('POST', `/api/${this.version}live_events/${eventId}/unmute_audio`);
return this.elementalClient.sendRequest('POST', `/live_events/${eventId}/unmute_audio`);
}
adjustAudioGain(eventId, gain) {
return this.elementalClient.sendRequest('POST', `/api/${this.version}live_events/${eventId}/adjust_audio_gain`, null, {gain});
return this.elementalClient.sendRequest('POST', `/live_events/${eventId}/adjust_audio_gain`, null, {gain});
}
eventPriority(eventId) {
return this.elementalClient.sendRequest('GET', `/api/${this.version}live_events/${eventId}/priority`);
return this.elementalClient.sendRequest('GET', `/live_events/${eventId}/priority`);
}
setEventPriority(eventId, priority) {
return this.elementalClient.sendRequest('POST', `/api/${this.version}live_events/${eventId}/priority`, null, {priority});
return this.elementalClient.sendRequest('POST', `/live_events/${eventId}/priority`, null, {priority});
}

@@ -53,3 +52,3 @@

activateInput(eventId, input_id) {
return this.elementalClient.sendRequest('POST', `/api/${this.version}live_events/${eventId}/activate_input`, null, {input_id});
return this.elementalClient.sendRequest('POST', `/live_events/${eventId}/activate_input`, null, {input_id});
}

@@ -56,0 +55,0 @@ }

@@ -37,3 +37,4 @@ const dateFormat = require('dateformat');

const reqHeaders = headers || {};
const url = path;
const url = this.version && ['PUT', 'POST'].includes(method)
? `/api/${this.version}${path}` : `/api${path}`;

@@ -40,0 +41,0 @@ return new Promise((resolve, reject) => {

@@ -5,23 +5,22 @@ class Resource {

this.name = name;
this.version = elementalClient.version ? `${elementalClient.version}/` : '';
}
create(opts) {
return this.elementalClient.sendRequest('POST', `/api/${this.version}${this.name}`, null, opts);
return this.elementalClient.sendRequest('POST', `/${this.name}`, null, opts);
}
retrieve(id) {
return this.elementalClient.sendRequest('GET', `/api/${this.version}${this.name}/${id}`);
return this.elementalClient.sendRequest('GET', `/${this.name}/${id}`);
}
update(id, opts) {
return this.elementalClient.sendRequest('PUT', `/api/${this.version}${this.name}/${id}`, null, opts);
return this.elementalClient.sendRequest('PUT', `/${this.name}/${id}`, null, opts);
}
delete(id) {
return this.elementalClient.sendRequest('DELETE', `/api/${this.version}${this.name}/${id}`);
return this.elementalClient.sendRequest('DELETE', `/${this.name}/${id}`);
}
list(opts) {
return this.elementalClient.sendRequest('GET', `/api/${this.version}${this.name}`, opts);
return this.elementalClient.sendRequest('GET', `/${this.name}`, opts);
}

@@ -28,0 +27,0 @@ }

{
"name": "elemental-live-client",
"version": "0.4.0",
"version": "0.5.0",
"description": "JS library to communicate with Elemental live API",

@@ -19,21 +19,21 @@ "directories": {

"devDependencies": {
"babel": "^6.5.2",
"babel-cli": "^6.22.2",
"babel-preset-es2015": "^6.22.0",
"babel-register": "^6.22.0",
"babel": "^6.23.0",
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-register": "^6.26.0",
"chai": "^4.2.0",
"codecov": "^3.5.0",
"eslint": "^6.3.0",
"eslint-config-standard": "^14.0.1",
"codecov": "^3.6.5",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-standard": "^4.0.1",
"istanbul": "v1.1.0-alpha.1",
"mocha": "^6.1.4",
"sinon": "^7.4.2"
"mocha": "^7.0.1",
"sinon": "^9.0.0"
},
"dependencies": {
"dateformat": "^3.0.3",
"request": "^2.79.0",
"xml2js": "^0.4.22"
"request": "^2.88.0",
"xml2js": "^0.4.23"
}
}

@@ -33,3 +33,3 @@ import {Device} from '../lib/device';

assert.deepEqual(data, previewImage);
assert(sendRequest.calledWith('POST', '/api/devices/123/preview', null, {
assert(sendRequest.calledWith('POST', '/devices/123/preview', null, {
'preview_images': {

@@ -69,25 +69,2 @@ 'preview_image': {

});
describe('generate preview', () => {
const retval = {};
const sendRequest = sinon.stub().returns(retval);
const dvc = new Device({sendRequest});
const result = dvc.generatePreview({id: '10', sourceType: 'DeviceInput,2,1,AJA,HD-SDI'});
const expectedBody = 'input_key=0&live_event[inputs_attributes][0][source_type]=DeviceInput,2,1,AJA,HD-SDI&live_event[inputs_attributes][0][device_input_attributes][sdi_settings_attributes][input_format]=Auto&live_event[inputs_attributes][0][device_input_attributes][device_id]=10';
const expectedHeaders = {
Accept: '*/*',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
};
assert.equal(result, retval);
assert(sendRequest.calledOnce);
const args = sendRequest.getCall(0).args;
assert.equal(args[0], 'POST');
assert.equal(args[1], '/inputs/generate_preview');
assert.equal(args[2], null);
assert.equal(args[3], expectedBody);
assert.deepEqual(args[4], expectedHeaders);
});
});

@@ -25,3 +25,3 @@ const assert = require('chai').assert;

return client.sendRequest('GET', '/api/live_events', {page: '3', 'per_page': 30}, null).
return client.sendRequest('GET', '/live_events', {page: '3', 'per_page': 30}, null).
then((data) => {

@@ -60,3 +60,3 @@ assert.deepEqual(data, eventList);

return client.sendRequest('POST', '/api/live_events', null, 'some nice data', {'Content-Type': 'text/plain'}).then(
return client.sendRequest('POST', '/live_events', null, 'some nice data', {'Content-Type': 'text/plain'}).then(
(data) => {

@@ -96,3 +96,3 @@ assert.deepEqual(data, eventList);

return client.sendRequest('POST', '/api/live_events', null, {name: 'My live event!'}).then(
return client.sendRequest('POST', '/live_events', null, {name: 'My live event!'}).then(
(data) => {

@@ -104,2 +104,59 @@ assert.deepEqual(data, eventList);

it('sendRequest should not include version number in GET requests', () => {
const client = new ElementalClient('http://my-elemental-server', null, 'v2.17.3.0');
const eventList = {'live_event_list': {
'live_event': [
{
'$': {href: '/live_events/1'},
name: 'Event 1',
input: {name: 'input_1'},
},
{
'$': {href: '/live_events/2'},
name: 'Event 2',
input: {name: 'input_1'},
},
],
}};
client.req = (opts, callback) => {
assert.deepEqual(opts, {
method: 'GET',
url: '/api/live_events',
qs: null,
headers: {},
body: null,
});
callback(null, {statusCode: 200, headers: {'content-type': 'application/xml'}}, xmlEventList);
};
return client.sendRequest('GET', '/live_events', null).then(
(data) => {
assert.deepEqual(data, eventList);
}
);
});
it('sendRequest should include version number in PUT requests', () => {
const client = new ElementalClient('http://my-elemental-server', null, 'v2.17.3.0');
const body = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><name>My live event!</name>';
client.req = (opts, callback) => {
assert.deepEqual(opts, {
method: 'PUT',
url: '/api/v2.17.3.0/live_events/5',
qs: null,
headers: {'Content-Type': 'application/xml'},
body,
});
callback(null, {statusCode: 200, headers: {'content-type': 'application/xml'}}, body);
};
return client.sendRequest('PUT', '/live_events/5', null, {name: 'My live event!'}).then(
(data) => {
assert.deepEqual(data, {name: 'My live event!'});
}
);
});
it('sendRequest should reject promise on request errors', (done) => {

@@ -112,3 +169,3 @@ const client = new ElementalClient('http://my-elemental-server');

client.sendRequest('GET', '/api/live_events/1233', null, null).then(
client.sendRequest('GET', '/live_events/1233', null, null).then(
() => assert(false),

@@ -129,3 +186,3 @@ (reason) => {

client.sendRequest('GET', '/api/live_events/1233', null, null).then(
client.sendRequest('GET', '/live_events/1233', null, null).then(
() => assert(false),

@@ -132,0 +189,0 @@ (reason) => {

@@ -30,3 +30,3 @@ import {LiveEvent} from '../lib/live-event';

assert.equal(result, testData.retval);
assert(testData.sendRequest.calledWith('GET', '/api/live_events/199/inputs'));
assert(testData.sendRequest.calledWith('GET', '/live_events/199/inputs'));
});

@@ -39,3 +39,3 @@

assert.equal(result, testData.retval);
assert(testData.sendRequest.calledWith('GET', '/api/live_events/199/status'));
assert(testData.sendRequest.calledWith('GET', '/live_events/199/status'));
});

@@ -48,3 +48,3 @@

assert.equal(result, testData.retval);
assert(testData.sendRequest.calledWith('GET', '/api/live_events/199/status', null, null, {'Accept': 'application/json'}));
assert(testData.sendRequest.calledWith('GET', '/live_events/199/status', null, null, {'Accept': 'application/json'}));
});

@@ -57,3 +57,3 @@

assert.equal(result, testData.retval);
assert(testData.sendRequest.calledWith('POST', '/api/live_events/195/start'));
assert(testData.sendRequest.calledWith('POST', '/live_events/195/start'));
});

@@ -66,3 +66,3 @@

assert.equal(result, testData.retval);
assert(testData.sendRequest.calledWith('POST', '/api/live_events/195/stop'));
assert(testData.sendRequest.calledWith('POST', '/live_events/195/stop'));
});

@@ -75,3 +75,3 @@

assert.equal(result, testData.retval);
assert(testData.sendRequest.calledWith('POST', '/api/live_events/195/cancel'));
assert(testData.sendRequest.calledWith('POST', '/live_events/195/cancel'));
});

@@ -84,3 +84,3 @@

assert.equal(result, testData.retval);
assert(testData.sendRequest.calledWith('POST', '/api/live_events/195/archive'));
assert(testData.sendRequest.calledWith('POST', '/live_events/195/archive'));
});

@@ -93,3 +93,3 @@

assert.equal(result, testData.retval);
assert(testData.sendRequest.calledWith('POST', '/api/live_events/195/reset'));
assert(testData.sendRequest.calledWith('POST', '/live_events/195/reset'));
});

@@ -102,3 +102,3 @@

assert.equal(result, testData.retval);
assert(testData.sendRequest.calledWith('POST', '/api/live_events/195/mute_audio'));
assert(testData.sendRequest.calledWith('POST', '/live_events/195/mute_audio'));
});

@@ -111,3 +111,3 @@

assert.equal(result, testData.retval);
assert(testData.sendRequest.calledWith('POST', '/api/live_events/195/unmute_audio'));
assert(testData.sendRequest.calledWith('POST', '/live_events/195/unmute_audio'));
});

@@ -120,3 +120,3 @@

assert.equal(result, testData.retval);
assert(testData.sendRequest.calledWith('POST', '/api/live_events/195/adjust_audio_gain', null, {'gain': 3}));
assert(testData.sendRequest.calledWith('POST', '/live_events/195/adjust_audio_gain', null, {'gain': 3}));
});

@@ -129,3 +129,3 @@

assert.equal(result, testData.retval);
assert(testData.sendRequest.calledWith('GET', '/api/live_events/199/priority'));
assert(testData.sendRequest.calledWith('GET', '/live_events/199/priority'));
});

@@ -138,3 +138,3 @@

assert.equal(result, testData.retval);
assert(testData.sendRequest.calledWith('POST', '/api/live_events/199/priority', null, {'priority': 1}));
assert(testData.sendRequest.calledWith('POST', '/live_events/199/priority', null, {'priority': 1}));
});

@@ -154,4 +154,4 @@

assert.equal(result, testData.retval);
assert(testData.sendRequest.calledWith('POST', '/api/live_events/195/activate_input', null, {'input_id': 465}));
assert(testData.sendRequest.calledWith('POST', '/live_events/195/activate_input', null, {'input_id': 465}));
});
});

@@ -7,5 +7,3 @@ import {Resource} from '../lib/resource';

const resourceName = 'stuff';
const resourceUrl = '/api/stuff';
const dummyVersion = '2.14'
const versionedUrl = `/api/${dummyVersion}/stuff`;
const resourceUrl = '/stuff';
const retval = {key: 'value'};

@@ -27,12 +25,2 @@ let client = {};

it('create with version', () => {
client.version = dummyVersion;
const resource = new Resource(client, resourceName);
const data = {name: 'Some stuff', description: 'Best stuff ever!'};
const result = resource.create(data);
assert.equal(result, retval);
assert(client.sendRequest.calledWith('POST', versionedUrl, null, data))
});
it('retrieve', () => {

@@ -46,11 +34,2 @@ const resource = new Resource(client, resourceName);

it('retrieve with version', () => {
client.version = dummyVersion;
const resource = new Resource(client, resourceName);
const result = resource.retrieve(10);
assert.equal(result, retval);
assert(client.sendRequest.calledWith('GET', `${versionedUrl}/10`))
});
it('update', () => {

@@ -65,12 +44,2 @@ const resource = new Resource(client, resourceName);

it('update with version', () => {
client.version = dummyVersion;
const resource = new Resource(client, resourceName);
const data = {description: 'Stuff number 10 (is this binary or decimal?)'}
const result = resource.update(10, data);
assert.equal(result, retval);
assert(client.sendRequest.calledWith('PUT', `${versionedUrl}/10`, null, data))
});
it('delete', () => {

@@ -84,11 +53,2 @@ const resource = new Resource(client, resourceName);

it('delete with version', () => {
client.version = dummyVersion;
const resource = new Resource(client, resourceName);
const result = resource.delete(10);
assert.equal(result, retval);
assert(client.sendRequest.calledWith('DELETE', `${versionedUrl}/10`))
});
it('list', () => {

@@ -101,11 +61,2 @@ const resource = new Resource(client, resourceName);

});
it('list with version', () => {
client.version = dummyVersion;
const resource = new Resource(client, resourceName);
const result = resource.list({page: 1});
assert.equal(result, retval);
assert(client.sendRequest.calledWith('GET', versionedUrl, {page: 1}))
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc