mirror of https://github.com/OpenVidu/openvidu.git
openvidu-node-client support for Angular 6 (axios and buffer dependecies)
parent
dcae9a0ac3
commit
12f300d916
|
@ -111,7 +111,7 @@
|
||||||
<li class="tsd-description">
|
<li class="tsd-description">
|
||||||
<aside class="tsd-sources">
|
<aside class="tsd-sources">
|
||||||
<ul>
|
<ul>
|
||||||
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L37">OpenVidu.ts:37</a></li>
|
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L35">OpenVidu.ts:35</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
<div class="tsd-comment tsd-typography">
|
<div class="tsd-comment tsd-typography">
|
||||||
|
@ -152,7 +152,7 @@
|
||||||
<li class="tsd-description">
|
<li class="tsd-description">
|
||||||
<aside class="tsd-sources">
|
<aside class="tsd-sources">
|
||||||
<ul>
|
<ul>
|
||||||
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L53">OpenVidu.ts:53</a></li>
|
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L51">OpenVidu.ts:51</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
<div class="tsd-comment tsd-typography">
|
<div class="tsd-comment tsd-typography">
|
||||||
|
@ -181,7 +181,7 @@
|
||||||
<li class="tsd-description">
|
<li class="tsd-description">
|
||||||
<aside class="tsd-sources">
|
<aside class="tsd-sources">
|
||||||
<ul>
|
<ul>
|
||||||
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L307">OpenVidu.ts:307</a></li>
|
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L294">OpenVidu.ts:294</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
<div class="tsd-comment tsd-typography">
|
<div class="tsd-comment tsd-typography">
|
||||||
|
@ -216,7 +216,7 @@
|
||||||
<li class="tsd-description">
|
<li class="tsd-description">
|
||||||
<aside class="tsd-sources">
|
<aside class="tsd-sources">
|
||||||
<ul>
|
<ul>
|
||||||
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L208">OpenVidu.ts:208</a></li>
|
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L201">OpenVidu.ts:201</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
<div class="tsd-comment tsd-typography">
|
<div class="tsd-comment tsd-typography">
|
||||||
|
@ -251,7 +251,7 @@
|
||||||
<li class="tsd-description">
|
<li class="tsd-description">
|
||||||
<aside class="tsd-sources">
|
<aside class="tsd-sources">
|
||||||
<ul>
|
<ul>
|
||||||
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L253">OpenVidu.ts:253</a></li>
|
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L243">OpenVidu.ts:243</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
<div class="tsd-comment tsd-typography">
|
<div class="tsd-comment tsd-typography">
|
||||||
|
@ -276,7 +276,7 @@
|
||||||
<li class="tsd-description">
|
<li class="tsd-description">
|
||||||
<aside class="tsd-sources">
|
<aside class="tsd-sources">
|
||||||
<ul>
|
<ul>
|
||||||
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L66">OpenVidu.ts:66</a></li>
|
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L64">OpenVidu.ts:64</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
<div class="tsd-comment tsd-typography">
|
<div class="tsd-comment tsd-typography">
|
||||||
|
@ -307,7 +307,7 @@
|
||||||
<li class="tsd-description">
|
<li class="tsd-description">
|
||||||
<aside class="tsd-sources">
|
<aside class="tsd-sources">
|
||||||
<ul>
|
<ul>
|
||||||
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L67">OpenVidu.ts:67</a></li>
|
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L65">OpenVidu.ts:65</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
<div class="tsd-comment tsd-typography">
|
<div class="tsd-comment tsd-typography">
|
||||||
|
@ -346,7 +346,7 @@
|
||||||
<li class="tsd-description">
|
<li class="tsd-description">
|
||||||
<aside class="tsd-sources">
|
<aside class="tsd-sources">
|
||||||
<ul>
|
<ul>
|
||||||
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L68">OpenVidu.ts:68</a></li>
|
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L66">OpenVidu.ts:66</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
<div class="tsd-comment tsd-typography">
|
<div class="tsd-comment tsd-typography">
|
||||||
|
@ -389,7 +389,7 @@
|
||||||
<li class="tsd-description">
|
<li class="tsd-description">
|
||||||
<aside class="tsd-sources">
|
<aside class="tsd-sources">
|
||||||
<ul>
|
<ul>
|
||||||
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L160">OpenVidu.ts:160</a></li>
|
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/OpenVidu.ts#L155">OpenVidu.ts:155</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
<div class="tsd-comment tsd-typography">
|
<div class="tsd-comment tsd-typography">
|
||||||
|
|
|
@ -114,7 +114,7 @@
|
||||||
<li class="tsd-description">
|
<li class="tsd-description">
|
||||||
<aside class="tsd-sources">
|
<aside class="tsd-sources">
|
||||||
<ul>
|
<ul>
|
||||||
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/Session.ts#L36">Session.ts:36</a></li>
|
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/Session.ts#L35">Session.ts:35</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
<h4 class="tsd-parameters-title">Parameters</h4>
|
<h4 class="tsd-parameters-title">Parameters</h4>
|
||||||
|
@ -145,7 +145,7 @@
|
||||||
<div class="tsd-signature tsd-kind-icon">properties<span class="tsd-signature-symbol">:</span> <a href="../interfaces/sessionproperties.html" class="tsd-signature-type">SessionProperties</a></div>
|
<div class="tsd-signature tsd-kind-icon">properties<span class="tsd-signature-symbol">:</span> <a href="../interfaces/sessionproperties.html" class="tsd-signature-type">SessionProperties</a></div>
|
||||||
<aside class="tsd-sources">
|
<aside class="tsd-sources">
|
||||||
<ul>
|
<ul>
|
||||||
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/Session.ts#L36">Session.ts:36</a></li>
|
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/Session.ts#L33">Session.ts:33</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
</section>
|
</section>
|
||||||
|
@ -155,7 +155,7 @@
|
||||||
<div class="tsd-signature tsd-kind-icon">session<wbr>Id<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
|
<div class="tsd-signature tsd-kind-icon">session<wbr>Id<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
|
||||||
<aside class="tsd-sources">
|
<aside class="tsd-sources">
|
||||||
<ul>
|
<ul>
|
||||||
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/Session.ts#L35">Session.ts:35</a></li>
|
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/Session.ts#L32">Session.ts:32</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
</section>
|
</section>
|
||||||
|
@ -172,7 +172,7 @@
|
||||||
<li class="tsd-description">
|
<li class="tsd-description">
|
||||||
<aside class="tsd-sources">
|
<aside class="tsd-sources">
|
||||||
<ul>
|
<ul>
|
||||||
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/Session.ts#L58">Session.ts:58</a></li>
|
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/Session.ts#L57">Session.ts:57</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
<div class="tsd-comment tsd-typography">
|
<div class="tsd-comment tsd-typography">
|
||||||
|
@ -201,7 +201,7 @@
|
||||||
<li class="tsd-description">
|
<li class="tsd-description">
|
||||||
<aside class="tsd-sources">
|
<aside class="tsd-sources">
|
||||||
<ul>
|
<ul>
|
||||||
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/Session.ts#L49">Session.ts:49</a></li>
|
<li>Defined in <a href="https://github.com/OpenVidu/openvidu/tree/master/openvidu-node-client/src/Session.ts#L48">Session.ts:48</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
<div class="tsd-comment tsd-typography">
|
<div class="tsd-comment tsd-typography">
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -14,22 +14,25 @@
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"docs": "grunt --gruntfile config/typedoc/custom-theme/gruntfile.js && typedoc --options ./config/typedoc/typedoc.js --out ./docs ./src && rm -rf ../../openvidu.io/api/openvidu-node-client/* && cp -R ./docs/. ../../openvidu.io/api/openvidu-node-client"
|
"docs": "grunt --gruntfile config/typedoc/custom-theme/gruntfile.js && typedoc --options ./config/typedoc/typedoc.js --out ./docs ./src && rm -rf ../../openvidu.io/api/openvidu-node-client/* && cp -R ./docs/. ../../openvidu.io/api/openvidu-node-client"
|
||||||
},
|
},
|
||||||
"dependencies": {},
|
"dependencies": {
|
||||||
|
"axios": "^0.18.0",
|
||||||
|
"buffer": "^5.1.0"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "9.6.6",
|
"@types/node": "10.3.0",
|
||||||
"ts-node": "6.0.0",
|
"ts-node": "6.1.0",
|
||||||
"tslint": "5.9.1",
|
"tslint": "5.10.0",
|
||||||
"typedoc": "^0.11.1",
|
"typedoc": "^0.11.1",
|
||||||
"typedoc-plugin-sourcefile-url": "^1.0.3",
|
"typedoc-plugin-sourcefile-url": "^1.0.3",
|
||||||
"typescript": "2.8.3",
|
"typescript": "2.9.1",
|
||||||
"grunt": "^1.0.1",
|
"grunt": "1.0.3",
|
||||||
"grunt-autoprefixer": "^3.0.4",
|
"grunt-autoprefixer": "3.0.4",
|
||||||
"grunt-cli": "^1.2.0",
|
"grunt-cli": "1.2.0",
|
||||||
"grunt-contrib-copy": "^1.0.0",
|
"grunt-contrib-copy": "1.0.0",
|
||||||
"grunt-contrib-sass": "^1.0.0",
|
"grunt-contrib-sass": "1.0.0",
|
||||||
"grunt-contrib-uglify": "^2.3.0",
|
"grunt-contrib-uglify": "3.3.0",
|
||||||
"grunt-contrib-watch": "~1.0.0",
|
"grunt-contrib-watch": "1.1.0",
|
||||||
"grunt-string-replace": "^1.0.0",
|
"grunt-string-replace": "1.3.1",
|
||||||
"grunt-ts": "^5.5.1"
|
"grunt-ts": "6.0.0-beta.19"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,10 +21,7 @@ import { Recording } from './Recording';
|
||||||
import { RecordingLayout } from './RecordingLayout';
|
import { RecordingLayout } from './RecordingLayout';
|
||||||
import { RecordingProperties } from './RecordingProperties';
|
import { RecordingProperties } from './RecordingProperties';
|
||||||
|
|
||||||
/**
|
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||||
* @hidden
|
|
||||||
*/
|
|
||||||
const https = require('https');
|
|
||||||
|
|
||||||
export class OpenVidu {
|
export class OpenVidu {
|
||||||
|
|
||||||
|
@ -35,6 +32,7 @@ export class OpenVidu {
|
||||||
private hostname: string;
|
private hostname: string;
|
||||||
private port: number;
|
private port: number;
|
||||||
private basicAuth: string;
|
private basicAuth: string;
|
||||||
|
private Buffer = require('buffer/').Buffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param urlOpenViduServer Public accessible IP where your instance of OpenVidu Server is up an running
|
* @param urlOpenViduServer Public accessible IP where your instance of OpenVidu Server is up an running
|
||||||
|
@ -82,19 +80,19 @@ export class OpenVidu {
|
||||||
public startRecording(sessionId: string, param2?: string | RecordingProperties): Promise<Recording> {
|
public startRecording(sessionId: string, param2?: string | RecordingProperties): Promise<Recording> {
|
||||||
return new Promise<Recording>((resolve, reject) => {
|
return new Promise<Recording>((resolve, reject) => {
|
||||||
|
|
||||||
let requestBody;
|
let data;
|
||||||
|
|
||||||
if (!!param2) {
|
if (!!param2) {
|
||||||
if (!(typeof param2 === 'string')) {
|
if (!(typeof param2 === 'string')) {
|
||||||
const properties = <RecordingProperties>param2;
|
const properties = <RecordingProperties>param2;
|
||||||
requestBody = JSON.stringify({
|
data = JSON.stringify({
|
||||||
session: sessionId,
|
session: sessionId,
|
||||||
name: !!properties.name ? properties.name : '',
|
name: !!properties.name ? properties.name : '',
|
||||||
recordingLayout: !!properties.recordingLayout ? properties.recordingLayout : '',
|
recordingLayout: !!properties.recordingLayout ? properties.recordingLayout : '',
|
||||||
customLayout: !!properties.customLayout ? properties.customLayout : ''
|
customLayout: !!properties.customLayout ? properties.customLayout : ''
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
requestBody = JSON.stringify({
|
data = JSON.stringify({
|
||||||
session: sessionId,
|
session: sessionId,
|
||||||
name: param2,
|
name: param2,
|
||||||
recordingLayout: '',
|
recordingLayout: '',
|
||||||
|
@ -102,7 +100,7 @@ export class OpenVidu {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
requestBody = JSON.stringify({
|
data = JSON.stringify({
|
||||||
session: sessionId,
|
session: sessionId,
|
||||||
name: '',
|
name: '',
|
||||||
recordingLayout: '',
|
recordingLayout: '',
|
||||||
|
@ -110,42 +108,39 @@ export class OpenVidu {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const options = {
|
axios.post(
|
||||||
hostname: this.hostname,
|
'https://' + this.hostname + ':' + this.port + OpenVidu.API_RECORDINGS + OpenVidu.API_RECORDINGS_START,
|
||||||
port: this.port,
|
data,
|
||||||
path: OpenVidu.API_RECORDINGS + OpenVidu.API_RECORDINGS_START,
|
{
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': this.basicAuth,
|
'Authorization': this.basicAuth,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json'
|
||||||
'Content-Length': Buffer.byteLength(requestBody)
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
)
|
||||||
const req = https.request(options, (res) => {
|
.then(res => {
|
||||||
let body = '';
|
if (res.status === 200) {
|
||||||
res.on('data', (d) => {
|
|
||||||
// Continuously update stream with data
|
|
||||||
body += d;
|
|
||||||
});
|
|
||||||
res.on('end', () => {
|
|
||||||
if (res.statusCode === 200) {
|
|
||||||
// SUCCESS response from openvidu-server (Recording in JSON format). Resolve new Recording
|
// SUCCESS response from openvidu-server (Recording in JSON format). Resolve new Recording
|
||||||
resolve(new Recording(JSON.parse(body)));
|
resolve(new Recording(res.data));
|
||||||
} else {
|
} else {
|
||||||
// ERROR response from openvidu-server. Resolve HTTP status
|
// ERROR response from openvidu-server. Resolve HTTP status
|
||||||
reject(new Error(res.statusCode));
|
reject(new Error(res.status.toString()));
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
if (error.response) {
|
||||||
|
// The request was made and the server responded with a status code (not 2xx)
|
||||||
|
reject(new Error(error.response.status.toString()));
|
||||||
|
} else if (error.request) {
|
||||||
|
// The request was made but no response was received
|
||||||
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||||
|
// http.ClientRequest in node.js
|
||||||
|
console.error(error.request);
|
||||||
|
} else {
|
||||||
|
// Something happened in setting up the request that triggered an Error
|
||||||
|
console.error('Error', error.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('error', (e) => {
|
|
||||||
reject(new Error(e));
|
|
||||||
});
|
|
||||||
req.write(requestBody);
|
|
||||||
req.end();
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -160,41 +155,39 @@ export class OpenVidu {
|
||||||
public stopRecording(recordingId: string): Promise<Recording> {
|
public stopRecording(recordingId: string): Promise<Recording> {
|
||||||
return new Promise<Recording>((resolve, reject) => {
|
return new Promise<Recording>((resolve, reject) => {
|
||||||
|
|
||||||
const options = {
|
axios.post(
|
||||||
hostname: this.hostname,
|
'https://' + this.hostname + ':' + this.port + OpenVidu.API_RECORDINGS + OpenVidu.API_RECORDINGS_STOP + '/' + recordingId,
|
||||||
port: this.port,
|
undefined,
|
||||||
path: OpenVidu.API_RECORDINGS + OpenVidu.API_RECORDINGS_STOP + '/' + recordingId,
|
{
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': this.basicAuth,
|
'Authorization': this.basicAuth,
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
)
|
||||||
const req = https.request(options, (res) => {
|
.then(res => {
|
||||||
let body = '';
|
if (res.status === 200) {
|
||||||
res.on('data', (d) => {
|
|
||||||
// Continuously update stream with data
|
|
||||||
body += d;
|
|
||||||
});
|
|
||||||
res.on('end', () => {
|
|
||||||
if (res.statusCode === 200) {
|
|
||||||
// SUCCESS response from openvidu-server (Recording in JSON format). Resolve new Recording
|
// SUCCESS response from openvidu-server (Recording in JSON format). Resolve new Recording
|
||||||
resolve(new Recording(JSON.parse(body)));
|
resolve(new Recording(res.data));
|
||||||
} else {
|
} else {
|
||||||
// ERROR response from openvidu-server. Resolve HTTP status
|
// ERROR response from openvidu-server. Resolve HTTP status
|
||||||
reject(new Error(res.statusCode));
|
reject(new Error(res.status.toString()));
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
if (error.response) {
|
||||||
|
// The request was made and the server responded with a status code (not 2xx)
|
||||||
|
reject(new Error(error.response.status.toString()));
|
||||||
|
} else if (error.request) {
|
||||||
|
// The request was made but no response was received
|
||||||
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||||
|
// http.ClientRequest in node.js
|
||||||
|
console.error(error.request);
|
||||||
|
} else {
|
||||||
|
// Something happened in setting up the request that triggered an Error
|
||||||
|
console.error('Error', error.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('error', (e) => {
|
|
||||||
reject(new Error(e));
|
|
||||||
});
|
|
||||||
// req.write();
|
|
||||||
req.end();
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -208,41 +201,38 @@ export class OpenVidu {
|
||||||
public getRecording(recordingId: string): Promise<Recording> {
|
public getRecording(recordingId: string): Promise<Recording> {
|
||||||
return new Promise<Recording>((resolve, reject) => {
|
return new Promise<Recording>((resolve, reject) => {
|
||||||
|
|
||||||
const options = {
|
axios.get(
|
||||||
hostname: this.hostname,
|
'https://' + this.hostname + ':' + this.port + OpenVidu.API_RECORDINGS + '/' + recordingId,
|
||||||
port: this.port,
|
{
|
||||||
path: OpenVidu.API_RECORDINGS + '/' + recordingId,
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': this.basicAuth,
|
'Authorization': this.basicAuth,
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
)
|
||||||
const req = https.request(options, (res) => {
|
.then(res => {
|
||||||
let body = '';
|
if (res.status === 200) {
|
||||||
res.on('data', (d) => {
|
|
||||||
// Continuously update stream with data
|
|
||||||
body += d;
|
|
||||||
});
|
|
||||||
res.on('end', () => {
|
|
||||||
if (res.statusCode === 200) {
|
|
||||||
// SUCCESS response from openvidu-server (Recording in JSON format). Resolve new Recording
|
// SUCCESS response from openvidu-server (Recording in JSON format). Resolve new Recording
|
||||||
resolve(new Recording(JSON.parse(body)));
|
resolve(new Recording(res.data));
|
||||||
} else {
|
} else {
|
||||||
// ERROR response from openvidu-server. Resolve HTTP status
|
// ERROR response from openvidu-server. Resolve HTTP status
|
||||||
reject(new Error(res.statusCode));
|
reject(new Error(res.status.toString()));
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
if (error.response) {
|
||||||
|
// The request was made and the server responded with a status code (not 2xx)
|
||||||
|
reject(new Error(error.response.status.toString()));
|
||||||
|
} else if (error.request) {
|
||||||
|
// The request was made but no response was received
|
||||||
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||||
|
// http.ClientRequest in node.js
|
||||||
|
console.error(error.request);
|
||||||
|
} else {
|
||||||
|
// Something happened in setting up the request that triggered an Error
|
||||||
|
console.error('Error', error.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('error', (e) => {
|
|
||||||
reject(new Error(e));
|
|
||||||
});
|
|
||||||
// req.write();
|
|
||||||
req.end();
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -253,46 +243,43 @@ export class OpenVidu {
|
||||||
public listRecordings(): Promise<Recording[]> {
|
public listRecordings(): Promise<Recording[]> {
|
||||||
return new Promise<Recording[]>((resolve, reject) => {
|
return new Promise<Recording[]>((resolve, reject) => {
|
||||||
|
|
||||||
const options = {
|
axios.get(
|
||||||
hostname: this.hostname,
|
'https://' + this.hostname + ':' + this.port + OpenVidu.API_RECORDINGS,
|
||||||
port: this.port,
|
{
|
||||||
path: OpenVidu.API_RECORDINGS,
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': this.basicAuth,
|
'Authorization': this.basicAuth,
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
)
|
||||||
const req = https.request(options, (res) => {
|
.then(res => {
|
||||||
let body = '';
|
if (res.status === 200) {
|
||||||
res.on('data', (d) => {
|
|
||||||
// Continuously update stream with data
|
|
||||||
body += d;
|
|
||||||
});
|
|
||||||
res.on('end', () => {
|
|
||||||
if (res.statusCode === 200) {
|
|
||||||
// SUCCESS response from openvidu-server (JSON arrays of recordings in JSON format). Resolve list of new recordings
|
// SUCCESS response from openvidu-server (JSON arrays of recordings in JSON format). Resolve list of new recordings
|
||||||
const recordingArray: Recording[] = [];
|
const recordingArray: Recording[] = [];
|
||||||
const responseItems = JSON.parse(body).items;
|
const responseItems = res.data.items;
|
||||||
for (const item of responseItems) {
|
for (const item of responseItems) {
|
||||||
recordingArray.push(new Recording(item));
|
recordingArray.push(new Recording(item));
|
||||||
}
|
}
|
||||||
resolve(recordingArray);
|
resolve(recordingArray);
|
||||||
} else {
|
} else {
|
||||||
// ERROR response from openvidu-server. Resolve HTTP status
|
// ERROR response from openvidu-server. Resolve HTTP status
|
||||||
reject(new Error(res.statusCode));
|
reject(new Error(res.status.toString()));
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
if (error.response) {
|
||||||
|
// The request was made and the server responded with a status code (not 2xx)
|
||||||
|
reject(new Error(error.response.status.toString()));
|
||||||
|
} else if (error.request) {
|
||||||
|
// The request was made but no response was received
|
||||||
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||||
|
// http.ClientRequest in node.js
|
||||||
|
console.error(error.request);
|
||||||
|
} else {
|
||||||
|
// Something happened in setting up the request that triggered an Error
|
||||||
|
console.error('Error', error.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('error', (e) => {
|
|
||||||
reject(new Error(e));
|
|
||||||
});
|
|
||||||
// req.write();
|
|
||||||
req.end();
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -307,45 +294,42 @@ export class OpenVidu {
|
||||||
public deleteRecording(recordingId: string): Promise<Error> {
|
public deleteRecording(recordingId: string): Promise<Error> {
|
||||||
return new Promise<Error>((resolve, reject) => {
|
return new Promise<Error>((resolve, reject) => {
|
||||||
|
|
||||||
const options = {
|
axios.delete(
|
||||||
hostname: this.hostname,
|
'https://' + this.hostname + ':' + this.port + OpenVidu.API_RECORDINGS + '/' + recordingId,
|
||||||
port: this.port,
|
{
|
||||||
path: OpenVidu.API_RECORDINGS + '/' + recordingId,
|
|
||||||
method: 'DELETE',
|
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': this.basicAuth,
|
'Authorization': this.basicAuth,
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
)
|
||||||
const req = https.request(options, (res) => {
|
.then(res => {
|
||||||
let body = '';
|
if (res.status === 204) {
|
||||||
res.on('data', (d) => {
|
|
||||||
// Continuously update stream with data
|
|
||||||
body += d;
|
|
||||||
});
|
|
||||||
res.on('end', () => {
|
|
||||||
if (res.statusCode === 204) {
|
|
||||||
// SUCCESS response from openvidu-server. Resolve undefined
|
// SUCCESS response from openvidu-server. Resolve undefined
|
||||||
resolve(undefined);
|
resolve(undefined);
|
||||||
} else {
|
} else {
|
||||||
// ERROR response from openvidu-server. Resolve HTTP status
|
// ERROR response from openvidu-server. Resolve HTTP status
|
||||||
reject(new Error(res.statusCode));
|
reject(new Error(res.status.toString()));
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
if (error.response) {
|
||||||
|
// The request was made and the server responded with a status code (not 2xx)
|
||||||
|
reject(new Error(error.response.status.toString()));
|
||||||
|
} else if (error.request) {
|
||||||
|
// The request was made but no response was received
|
||||||
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||||
|
// http.ClientRequest in node.js
|
||||||
|
console.error(error.request);
|
||||||
|
} else {
|
||||||
|
// Something happened in setting up the request that triggered an Error
|
||||||
|
console.error('Error', error.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('error', (e) => {
|
|
||||||
reject(new Error(e));
|
|
||||||
});
|
|
||||||
// req.write();
|
|
||||||
req.end();
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getBasicAuth(secret: string): string {
|
private getBasicAuth(secret: string): string {
|
||||||
return 'Basic ' + (new Buffer('OPENVIDUAPP:' + secret).toString('base64'));
|
return 'Basic ' + this.Buffer('OPENVIDUAPP:' + secret).toString('base64');
|
||||||
}
|
}
|
||||||
|
|
||||||
private setHostnameAndPort(): void {
|
private setHostnameAndPort(): void {
|
||||||
|
|
|
@ -22,10 +22,7 @@ import { RecordingMode } from './RecordingMode';
|
||||||
import { SessionProperties } from './SessionProperties';
|
import { SessionProperties } from './SessionProperties';
|
||||||
import { TokenOptions } from './TokenOptions';
|
import { TokenOptions } from './TokenOptions';
|
||||||
|
|
||||||
/**
|
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||||
* @hidden
|
|
||||||
*/
|
|
||||||
const https = require('https');
|
|
||||||
|
|
||||||
export class Session {
|
export class Session {
|
||||||
|
|
||||||
|
@ -35,6 +32,8 @@ export class Session {
|
||||||
sessionId: string;
|
sessionId: string;
|
||||||
properties: SessionProperties;
|
properties: SessionProperties;
|
||||||
|
|
||||||
|
private Buffer = require('buffer/').Buffer;
|
||||||
|
|
||||||
constructor(private hostname: string, private port: number, private basicAuth: string, properties?: SessionProperties) {
|
constructor(private hostname: string, private port: number, private basicAuth: string, properties?: SessionProperties) {
|
||||||
if (!properties) {
|
if (!properties) {
|
||||||
this.properties = {};
|
this.properties = {};
|
||||||
|
@ -58,48 +57,45 @@ export class Session {
|
||||||
public generateToken(tokenOptions?: TokenOptions): Promise<string> {
|
public generateToken(tokenOptions?: TokenOptions): Promise<string> {
|
||||||
return new Promise<string>((resolve, reject) => {
|
return new Promise<string>((resolve, reject) => {
|
||||||
|
|
||||||
const requestBody = JSON.stringify({
|
const data = JSON.stringify({
|
||||||
session: this.sessionId,
|
session: this.sessionId,
|
||||||
role: (!!tokenOptions && !!tokenOptions.role) ? tokenOptions.role : OpenViduRole.PUBLISHER,
|
role: (!!tokenOptions && !!tokenOptions.role) ? tokenOptions.role : OpenViduRole.PUBLISHER,
|
||||||
data: (!!tokenOptions && !!tokenOptions.data) ? tokenOptions.data : ''
|
data: (!!tokenOptions && !!tokenOptions.data) ? tokenOptions.data : ''
|
||||||
});
|
});
|
||||||
|
|
||||||
const options = {
|
axios.post(
|
||||||
hostname: this.hostname,
|
'https://' + this.hostname + ':' + this.port + Session.API_TOKENS,
|
||||||
port: this.port,
|
data,
|
||||||
path: Session.API_TOKENS,
|
{
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': this.basicAuth,
|
'Authorization': this.basicAuth,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json'
|
||||||
'Content-Length': Buffer.byteLength(requestBody)
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
)
|
||||||
const req = https.request(options, (res) => {
|
.then(res => {
|
||||||
let body = '';
|
if (res.status === 200) {
|
||||||
res.on('data', (d) => {
|
|
||||||
// Continuously update stream with data
|
|
||||||
body += d;
|
|
||||||
});
|
|
||||||
res.on('end', () => {
|
|
||||||
if (res.statusCode === 200) {
|
|
||||||
// SUCCESS response from openvidu-server. Resolve token
|
// SUCCESS response from openvidu-server. Resolve token
|
||||||
const parsed = JSON.parse(body);
|
resolve(res.data.id);
|
||||||
resolve(parsed.id);
|
|
||||||
} else {
|
} else {
|
||||||
// ERROR response from openvidu-server. Resolve HTTP status
|
// ERROR response from openvidu-server. Resolve HTTP status
|
||||||
reject(new Error(res.statusCode));
|
reject(new Error(res.status.toString()));
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
if (error.response) {
|
||||||
|
// The request was made and the server responded with a status code (not 2xx)
|
||||||
|
reject(new Error(error.response.status.toString()));
|
||||||
|
} else if (error.request) {
|
||||||
|
// The request was made but no response was received
|
||||||
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||||
|
// http.ClientRequest in node.js
|
||||||
|
console.error(error.request);
|
||||||
|
} else {
|
||||||
|
// Something happened in setting up the request that triggered an Error
|
||||||
|
console.error('Error', error.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('error', (e) => {
|
|
||||||
reject(e);
|
|
||||||
});
|
|
||||||
req.write(requestBody);
|
|
||||||
req.end();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,7 +108,7 @@ export class Session {
|
||||||
resolve(this.sessionId);
|
resolve(this.sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestBody = JSON.stringify({
|
const data = JSON.stringify({
|
||||||
mediaMode: !!this.properties.mediaMode ? this.properties.mediaMode : MediaMode.ROUTED,
|
mediaMode: !!this.properties.mediaMode ? this.properties.mediaMode : MediaMode.ROUTED,
|
||||||
recordingMode: !!this.properties.recordingMode ? this.properties.recordingMode : RecordingMode.MANUAL,
|
recordingMode: !!this.properties.recordingMode ? this.properties.recordingMode : RecordingMode.MANUAL,
|
||||||
defaultRecordingLayout: !!this.properties.defaultRecordingLayout ? this.properties.defaultRecordingLayout : RecordingLayout.BEST_FIT,
|
defaultRecordingLayout: !!this.properties.defaultRecordingLayout ? this.properties.defaultRecordingLayout : RecordingLayout.BEST_FIT,
|
||||||
|
@ -120,47 +116,46 @@ export class Session {
|
||||||
customSessionId: !!this.properties.customSessionId ? this.properties.customSessionId : ''
|
customSessionId: !!this.properties.customSessionId ? this.properties.customSessionId : ''
|
||||||
});
|
});
|
||||||
|
|
||||||
const options = {
|
axios.post(
|
||||||
hostname: this.hostname,
|
'https://' + this.hostname + ':' + this.port + Session.API_SESSIONS,
|
||||||
port: this.port,
|
data,
|
||||||
path: Session.API_SESSIONS,
|
{
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': this.basicAuth,
|
'Authorization': this.basicAuth,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json'
|
||||||
'Content-Length': Buffer.byteLength(requestBody)
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
)
|
||||||
const req = https.request(options, (res) => {
|
.then(res => {
|
||||||
let body = '';
|
if (res.status === 200) {
|
||||||
res.on('data', (d) => {
|
// SUCCESS response from openvidu-server. Resolve token
|
||||||
// Continuously update stream with data
|
this.sessionId = res.data.id;
|
||||||
body += d;
|
resolve(this.sessionId);
|
||||||
});
|
} else {
|
||||||
res.on('end', () => {
|
// ERROR response from openvidu-server. Resolve HTTP status
|
||||||
if (res.statusCode === 200) {
|
reject(new Error(res.status.toString()));
|
||||||
// SUCCESS response from openvidu-server. Resolve sessionId
|
}
|
||||||
const parsed = JSON.parse(body);
|
}).catch(error => {
|
||||||
this.sessionId = parsed.id;
|
if (error.response) {
|
||||||
resolve(parsed.id);
|
// The request was made and the server responded with a status code (not 2xx)
|
||||||
} else if (res.statusCode === 409) {
|
if (error.response.status === 409) {
|
||||||
// 'customSessionId' already existed
|
// 'customSessionId' already existed
|
||||||
this.sessionId = this.properties.customSessionId;
|
this.sessionId = this.properties.customSessionId;
|
||||||
resolve(this.sessionId);
|
resolve(this.sessionId);
|
||||||
} else {
|
} else {
|
||||||
// ERROR response from openvidu-server. Resolve HTTP status
|
reject(new Error(error.response.status.toString()));
|
||||||
reject(new Error(res.statusCode));
|
}
|
||||||
|
} else if (error.request) {
|
||||||
|
// The request was made but no response was received
|
||||||
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||||
|
// http.ClientRequest in node.js
|
||||||
|
console.error(error.request);
|
||||||
|
} else {
|
||||||
|
// Something happened in setting up the request that triggered an Error
|
||||||
|
console.error('Error', error.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('error', (e) => {
|
|
||||||
reject(e);
|
|
||||||
});
|
|
||||||
req.write(requestBody);
|
|
||||||
req.end();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue