An implementation of the StreamLive (Caldera) API calls in nodeJS
It aims to help integrators to code the StreamLive connectors properly, and to match the API requirements. Typically, the bleeding-edge version of the API should match with the this connector master branch.
a big change from the old streamlive-sdk-js is that this implementation is modular. that means you can choose to use different modules, config files, logging system for each part of your application, depending on the need. and everything is configurable, with no default value.
the reason to do this is that we the connector's implementation shouldn't be entirely based on other peoples project that can trap us in law/technical problems in the long term.
in practice we use widely used open-source tools (nconf, nedb, bunyan, express to develop the connectors, but with this technique we might develop our own modules.
WARNING This may change soon
like in the old streamlive-sdk-js, javascript promises are used to return asynchronously values from the api. the q module is used to manage this. this is not the best solution but for the moment it does the work, i don't think the module will be abandoned soon.
WARNING This may change soon
the main usage is to be required by other connectors by installing
npm install -P streamlive-api
(note that this wrapper around the API doesn't serve a connector, you should also manage this by your own ways)
instantiate the api
var config = {
'SL_API_URL': 'http://api.linux-malves.caldera.com',
'SL_API_ID': '5a8c336f86a2ef6b1bcabb28',
'SL_API_SECRET': '595d44e295e8b8e2a8f8d08822056d895a8c3370006374.63342540'
'logger': bunyan({
name: 'Streamlive Connector - Export - API'
});
};
// You can also use a file and parse it's content in a json object.
var api = require('streamlive-api')(config);
use the api
api.requestToken()
.then(function () {
return api.getTemplates();
})
.then(function (templates) {
// do something with the result of your call
})
.catch(function (err) {
// handle errors
// in most case the errors will be HTTP errors sent back by the API,
// a good practice is to make a switch like this :
switch (err.code) {
case 404:
logger.error('Error 404', err);
break;
case 500:
logger.error('Error 500', err);
break;
// and so on...
}
});
just clone the repo and get into it
create a generic connector in streamlive, copy connector id and secret into the config.json variables (connector_id, connector_secret) and specify the correct URL and ports so the connector can access to your API
then make a npm install
to install requirements
and grunt
to compile files and run tests
a non-technician should be able to run the tests when the API gets updated, so it will be a TODO
to create an environment where the connectors compability with the API can be tested. of course this is maintenance work and should be included in a long term development process. tests results are stored as xml files in the "report" folder
the logs are stored in "logs", the files prefixed by "test-" are the test logs, that will be done after each run of the test suite. this is useful to have a return on the API return values the API logs are all bunyan format every API call is logged verbosely by default, if you write a production connector you may configure it for less verbosity in logs
run grunt doc
to generate html documentation in the doc folder.
the documentation is specified directly in the slapi source with the JSDoc syntax.
you can access the documentation via CURRENT_FOLDER/doc/global.html
TODO
reliability of the info should be improved
TODO
check token returned by requestToken