NodeJS and Kaltura API

Anyone using Kaltura with NodeJS and Express ?

Yup:) In fact, developer.kaltura.org does.

I am trying to get the basic auth working , but keep getting “toParams not set Error”

var cb = function(results) {
    if(results) {
        console.log(results);
    } else {
        console.log("No results");
    }
};

var Kaltura = require('../KalturaGeneratedAPIClientsNodeJS/KalturaClient.js');
var ktypes = require('../KalturaGeneratedAPIClientsNodeJS/KalturaTypes');

var partnerId = 1111111;
var secret = 'xxxxxxx';

var config = new Kaltura.KalturaConfiguration(yyyyyy);
config.serviceUrl = "https://www.kaltura.com/";
var client = new Kaltura.KalturaClient(config);

var userId = null;
var type = ktypes.KalturaSessionType.ADMIN;

var expiry = null;
var privileges = null;
var result = client.session(cb, secret, userId, type, partnerId, expiry, privileges);

Can anyone help ?

Hello,

As I replied in https://github.com/kaltura/KalturaGeneratedAPIClientsNodeJS/issues/3#issuecomment-154104460 the code works for me.

var Kaltura = require('./KalturaClient');
var config = new Kaltura.KalturaConfiguration(partner_id);
config.serviceUrl = "https://www.kaltura.com/";
var client = new Kaltura.KalturaClient(config);
client.session.start(function(ks) {
    if (ks.code && ks.message) {
        console.log('Error starting session', success, ks);
    } else {
        client.setKs(ks);
        console.log(ks);
    }
}, "admin_secret",
"userid@kaltura.com",
Kaltura.enums.KalturaSessionType.ADMIN,partner_id,null,null);

Please provide a backtrace…

Thanks,

toParams is not defined

ReferenceError: toParams is not defined
at Object.<anonymous> (/home/avrono/workspace/knowledgemotion/km-api/KalturaGeneratedAPIClientsNodeJS/KalturaClientBase.js:124:36)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (/home/avrono/workspace/knowledgemotion/km-api/KalturaGeneratedAPIClientsNodeJS/KalturaClient.js:33:15)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)</pre></body></html>

Might it be because I pulled the sources “clone” and did not install with npm ?

I think you may be missing some supporting modules.
I suggest you install the npm from https://www.npmjs.com/package/kaltura
and then, if it still does not work, debug by running a simple snippet from CLI like so:
# nodejs /path/to/snippet.js

You can clone directly, that is also fine but in that case, make sure you also install utils, fs, url, path, http, crypto

1 Like

cheers will give it a try …

Is there something wrong with the way modules are packed with “npm install kaltura” … should the .js files not be in /lib ?

Its a matter of choice really. There is no unified standard. As long as your require path to the actual JS is correct, it will work.

so

npm install kaltura from project root …

have ./node_modules
…/kaltura

var kaltura = require(‘kaltura’)

output :smile:

toParams is not defined

ReferenceError: toParams is not defined
at Object.&lt;anonymous&gt; (/home/avrono/workspace/knowledgemotion/km-api/node_modules/kaltura/KalturaClientBase.js:124:36)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.&lt;anonymous&gt; (/home/avrono/workspace/knowledgemotion/km-api/node_modules/kaltura/KalturaClient.js:33:15)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)</pre></body></html>

Ok, seems to work … convention var kaltura not var Kaltura :smile:

Jess I still seem to be getting errors when integrating in my project.

Is there any reason that line 124 ofr KalturaClientBase.js reads:

 module.exports.toParams = toParams = function(obj) {

I have not done a full analysis, but this seems to cause an error with Node 4.x.x and express 4

If I change this to:

module.exports.toParmas = function(obj) {

Error goes way …

It should probalbly read :

 var toParams = module.exports.toParams = function(obj)

Hello @avrono,

Thanks for the report, you fix seems correct. The clientlibs are all auto generated from https://github.com/kaltura/server/blob/Kajam-11.2.0/generator/sources/node/KalturaClientBase.js and the issue seems to stem from there.
Will handle it.

Thanks for reporting it,

FYI - this was resolved in this pull:

I will release a new NPM soon but you can manually patch your source as well.

FYI - version 3.3.0 released here: https://www.npmjs.com/package/kaltura
Also added a small test.js file to it with the following:

var kaltura = require('kaltura');

partner_id=102;
service_url='https://www.kaltura.com';
secret='';
var kaltura_conf = new kaltura.kc.KalturaConfiguration(partner_id);
kaltura_conf.serviceUrl = service_url ;
var client = new kaltura.kc.KalturaClient(kaltura_conf);
var type = kaltura.kc.enums.KalturaSessionType.ADMIN;

var expiry = null;
var privileges = null;
var ks = client.session.start(print_ks,secret , 'some@user.com', type, partner_id, expiry, privileges);

function print_ks(result)
{
        console.log(result);
}

Just to help people get started.
Would love to get a pull request with more serious unit testing.