Skip to content

Commit

Permalink
Fix Javascript library for Gstd
Browse files Browse the repository at this point in the history
  • Loading branch information
lleon95 committed Oct 2, 2020
2 parents 0155675 + a7fac13 commit d924fcb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 44 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dnl required version of autoconf
AC_PREREQ([2.53])

dnl Gstreamer's daemon package name and version
AC_INIT([gstd],[0.11.2])
AC_INIT([gstd],[0.11.3])

dnl required version of gstreamer and gst-plugins-base
GST_REQUIRED=1.0.0
Expand Down
91 changes: 48 additions & 43 deletions libgstc/javascript/libgstc.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class GstdClient {
* @param {String} ip.
* @param {Number} port.
*/
constructor(ip='http://localhost',port=5000) {
constructor(ip = '127.0.0.1', port = 5000) {

this.ip = ip;
this.port = port;
Expand All @@ -48,30 +48,31 @@ class GstdClient {
/**
* Send Command.
*
* @param {String} url.
* @param {String} address.
* @param {Array} request.
*
* @throws {GstdError} Triggered when Gstd fails to process a request.
* @throws {GstcError} Triggered when GstClient fails.
*
* @return {object} Response from Gstd.
*/
static async send_cmd(url, request) {

static async send_cmd(address, request) {
/* Add scheme to the address (authority + path + query) */
const url = `http://${address}`;
try {
var response = await fetch (url, request);
var response = await fetch(url, request);
var j_resp = await response.json();
} catch (e) {
if(e instanceof TypeError &&
e.message.includes("NetworkError")) {
if (e instanceof TypeError &&
e.message.includes("NetworkError")) {
throw new GstcError(['Gstd did not respond. Is it up?',
GstcErrorCode.GSTC_UNREACHABLE]);
GstcErrorCode.GSTC_UNREACHABLE]);
} else {
throw new GstcError(['Gstd corrupted response',
GstcErrorCode.GSTC_RECV_ERROR]);
GstcErrorCode.GSTC_RECV_ERROR]);
}
}
if (j_resp["code"] !== GstcErrorCode.GSTC_OK ) {
if (j_resp["code"] !== GstcErrorCode.GSTC_OK) {
throw new GstdError([j_resp["description"], j_resp["code"]]);
}
return j_resp;
Expand All @@ -91,23 +92,25 @@ class GstdClient {
*/
async create(uri, name, description) {

var complete_uri = this.ip + ":" + this.port + uri + "?name=" + name;
var complete_address = this.ip + ":" + this.port + uri + "?name=" +
name;

/* Allow create without description */
if (description != null) {
complete_uri = complete_uri + "&description=" + description;
complete_address = complete_address + "&description=" +
description;
}

var request = {
method: 'POST',
body : {
uri : uri,
name : name,
description : description
body: {
uri: uri,
name: name,
description: description
}
}

return GstdClient.send_cmd(complete_uri, request);
return GstdClient.send_cmd(complete_address, request);
}

/**
Expand All @@ -122,9 +125,9 @@ class GstdClient {
*/
async read(uri) {

var complete_uri = this.ip + ":" + this.port + uri;
var request = { method : "GET" };
return GstdClient.send_cmd(complete_uri, request);
var complete_address = this.ip + ":" + this.port + uri;
var request = { method: "GET" };
return GstdClient.send_cmd(complete_address, request);
}

/**
Expand All @@ -138,18 +141,19 @@ class GstdClient {
*
* @return {object} Response from Gstd.
*/
async update(uri, description){
async update(uri, description) {

var complete_uri = this.ip + ":" + this.port + uri + "?name=" + description;
var complete_address = this.ip + ":" + this.port + uri + "?name=" +
description;
var request = {
method: 'PUT',
body: {
uri : uri,
description : description
uri: uri,
description: description
},
}

return GstdClient.send_cmd(complete_uri, request);
return GstdClient.send_cmd(complete_address, request);
}

/**
Expand All @@ -163,16 +167,17 @@ class GstdClient {
* @return {object} Response from Gstd.
*/
async delete(uri, name) {
var complete_uri = this.ip + ":" + this.port + uri + "?name=" + name;
var complete_address = this.ip + ":" + this.port + uri + "?name="
+ name;
var request = {
method: 'DELETE',
body: {
uri : uri,
name : name
uri: uri,
name: name
},
}

return GstdClient.send_cmd(complete_uri, request);
return GstdClient.send_cmd(complete_address, request);
}

/**
Expand Down Expand Up @@ -348,8 +353,8 @@ class GstdClient {
*
* @return {object} Response from Gstd.
*/
async event_seek(pipe_name, rate=1.0, format=3, flags=1, start_type=1,
start=0, end_type=1, end=-1) {
async event_seek(pipe_name, rate = 1.0, format = 3, flags = 1,
start_type = 1, start = 0, end_type = 1, end = -1) {

var uri = "/pipelines/" + pipe_name + "/event";
var description = rate + "%20" + format + "%20" + flags + "%20" +
Expand All @@ -367,7 +372,7 @@ class GstdClient {
*
* @return {object} Response from Gstd.
*/
async debug_color (enable) {
async debug_color(enable) {

return this.update("/debug/color", enable);
}
Expand Down Expand Up @@ -617,17 +622,17 @@ class GstdClient {
return this.read("/pipelines/" + pipe_name + "/graph");
}

/**
* Set the pipeline verbose mode.
* Only supported on GST Version >= 1.10
*
* @param {String} pipe_name.
*
* @throws {GstdError} Triggered when Gstd fails to process a request.
* @throws {Boolean} Triggered when GstClient fails.
*
* @return {object} Response from Gstd.
*/
/**
* Set the pipeline verbose mode.
* Only supported on GST Version >= 1.10
*
* @param {String} pipe_name.
*
* @throws {GstdError} Triggered when Gstd fails to process a request.
* @throws {Boolean} Triggered when GstClient fails.
*
* @return {object} Response from Gstd.
*/
pipeline_verbose(pipe_name, enable) {
return this.update("/pipelines/" + pipe_name + "/verbose", enable);
}
Expand Down

0 comments on commit d924fcb

Please sign in to comment.