Skip to content

Commit

Permalink
New clientlib ver
Browse files Browse the repository at this point in the history
  • Loading branch information
KalturaCommunity committed Feb 17, 2022
1 parent 2350095 commit 1f1f7eb
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 44 deletions.
6 changes: 3 additions & 3 deletions KalturaClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// to do with audio, video, and animation what Wiki platforms allow them to do with
// text.
//
// Copyright (C) 2006-2021 Kaltura Inc.
// Copyright (C) 2006-2022 Kaltura Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -42,8 +42,8 @@ class Client extends kaltura.ClientBase {
*/
constructor(config) {
super(config);
this.setApiVersion('17.18.0');
this.setClientTag('node:22-02-15');
this.setApiVersion('17.19.0');
this.setClientTag('node:22-02-16');
}
}

Expand Down
76 changes: 48 additions & 28 deletions KalturaClientBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// to do with audio, video, and animation what Wiki platfroms allow them to do with
// text.
//
// Copyright (C) 2006-2011 Kaltura Inc.
// Copyright (C) 2006-2022 Kaltura Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
Expand All @@ -32,7 +32,8 @@ const fs = require('fs');
const path = require('path');
const http = require('http');
const https = require('https');
const request = require('request');
const axios = require('axios');
const url = require('url');

const kaltura = require('./KalturaRequestData');

Expand Down Expand Up @@ -163,21 +164,38 @@ class ClientBase extends kaltura.RequestData {
*/
setConfig(config) {
this.config = config;
const axiosDefaultConfig = {
baseURL: config.serviceUrl,
timeout: config.timeout,
};
if (config.getLogger() instanceof ILogger) {
this.shouldLog = true;
}
const options = {
timeout: config.timeout,
uri: config.serviceUrl,
};
if (config.agentOptions) {
const httpInterface = options.uri.startsWith('https') ? https : http;
options.agent = new httpInterface.Agent(config.agentOptions);
}
if (config.proxy) {
options.proxy = config.proxy;
// we only need this because in the past, we used the `request` module, which had a different way of
// setting proxy config and we don't want to introduce breaking changes
let myproxy = url.parse(config.proxy, true);
let proxy = {
host: myproxy.hostname,
port: myproxy.port
}
if (myproxy.protocol == 'https:'){
proxy.protocol = 'https';
}
if (myproxy.auth){
let creds = myproxy.auth.split(':');
proxy.auth = {
username: creds[0],
password: creds[1]
}
}
console.log('Using a HTTP proxy:');
console.log(proxy);
axiosDefaultConfig.proxy = proxy;
}
this.request = request.defaults(options);

this.axios = axios.create(axiosDefaultConfig);

}

/**
Expand Down Expand Up @@ -260,8 +278,8 @@ class RequestBuilder extends kaltura.VolatileRequestData {
let headers = this.getHeaders(client);

let options = {
uri: requestUrl,
method: 'POST',
url: requestUrl,
method: 'post',
headers: headers
};

Expand Down Expand Up @@ -309,18 +327,10 @@ class RequestBuilder extends kaltura.VolatileRequestData {
body = jsonBody;
}

options.body = body;

client.request(options, (err, response, data) => {
if (err) {
if (callback) {
callback(false, err);
return;
}
else {
throw new Error(json.message);
}
}
options.data = body;
//console.log ('LOVE');
client.axios(options)
.then((response) => {
let sessionId;
let serverId;
for (var header in response.headers) {
Expand All @@ -331,12 +341,13 @@ class RequestBuilder extends kaltura.VolatileRequestData {
sessionId = response.headers[header];
}
}
client.debug('Response server [' + serverId + '] session [' + sessionId + ']: ' + data);
client.debug('Response server [' + serverId + '] session [' + sessionId + ']: ' + response.data);

let json;
try {
json = JSON.parse(data);
json = response.data;
} catch (err) {
client.log(err.toString());
json = {
error: err
}
Expand All @@ -360,6 +371,15 @@ class RequestBuilder extends kaltura.VolatileRequestData {
else if (callback) {
callback(true, json);
}
}, (err) => {
client.log(err.toString());
if (callback) {
callback(false, err);
return;
}
else {
throw new Error(json.message);
}
});
}

Expand Down
2 changes: 1 addition & 1 deletion KalturaModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// to do with audio, video, and animation what Wiki platforms allow them to do with
// text.
//
// Copyright (C) 2006-2021 Kaltura Inc.
// Copyright (C) 2006-2022 Kaltura Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
Expand Down
2 changes: 1 addition & 1 deletion KalturaRequestData.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// to do with audio, video, and animation what Wiki platforms allow them to do with
// text.
//
// Copyright (C) 2006-2021 Kaltura Inc.
// Copyright (C) 2006-2022 Kaltura Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
Expand Down
2 changes: 1 addition & 1 deletion KalturaServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// to do with audio, video, and animation what Wiki platforms allow them to do with
// text.
//
// Copyright (C) 2006-2021 Kaltura Inc.
// Copyright (C) 2006-2022 Kaltura Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
Expand Down
7 changes: 6 additions & 1 deletion KalturaTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// to do with audio, video, and animation what Wiki platforms allow them to do with
// text.
//
// Copyright (C) 2006-2021 Kaltura Inc.
// Copyright (C) 2006-2022 Kaltura Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -5743,6 +5743,11 @@ ENGAGEMENT_BREAKDOWN_WEBCAST : '40010',
ENGAGMENT_TIMELINE_WEBCAST : '40011',
ENGAGEMENT_TOOLS_WEBCAST : '40012',
REACTIONS_BREAKDOWN_WEBCAST : '40013',
VE_HIGHLIGHTS : '50000',
VE_REGISTERED_PLATFORMS : '50001',
VE_REGISTERED_INDUSTRY : '50002',
VE_REGISTERED_ROLES : '50003',
VE_REGISTERED_COUNTRIES : '50004',
};

module.exports.ResetPassLinkType = {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Kaltura node.js API Client Library.
Compatible with Kaltura server version 17.18.0 and above.
Compatible with Kaltura server version 17.19.0 and above.
This client library replaces the older architecture that presented in previous node.js client library.

[![NPM](https://nodei.co/npm/kaltura-client.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/kaltura-client/)
Expand Down
2 changes: 1 addition & 1 deletion example.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function session_start(){
}

client.setKs(ks);
console.log("Seesion started: " + ks);
console.log("Session started: " + ks);
resolve();
})
.execute(client);
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "kaltura-client",
"version": "17.18.0",
"version": "17.19.0",
"description": "Kaltura NodeJS client library (new implementation)",
"main": "KalturaClient.js",
"scripts": {
"test": "./node_modules/.bin/mocha --timeout 60000"
},
"engines": {
"node": ">= 6.0.0"
"node": ">= 10.0.0"
},
"repository": {
"type": "git",
Expand All @@ -27,15 +27,15 @@
"url": "https://github.com/kaltura/clients-generator/issues"
},
"dependencies": {
"md5": "*",
"path": "*",
"axios": "^0.21.2",
"http": "*",
"https": "*",
"request": "~2.88.0"
"md5": "*",
"path": "*"
},
"devDependencies": {
"shortid": "^2.2.8",
"chai": "^4.1.2",
"mocha": "^5.2.0"
"mocha": "^9.1.4",
"shortid": "^2.2.8"
}
}
9 changes: 9 additions & 0 deletions test/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ const {secret, partnerId, serviceUrl} = testConfig;
let config = new kaltura.Configuration();
config.serviceUrl = serviceUrl;

// Uncomment if proxy is needed
/*
const proxyUrl = new URL('http://127.0.0.1:3128');
proxyUrl.username = 'user';
proxyUrl.password = 'pass';
config.proxy = proxyUrl.toString();
*/

const client = new kaltura.Client(config);


Expand Down

0 comments on commit 1f1f7eb

Please sign in to comment.