Skip to content

Commit

Permalink
Added custom headers for BasicClient
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkonst committed Aug 19, 2022
1 parent d76bca2 commit 6940d75
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ulms/api-clients",
"version": "5.9.1",
"version": "5.10.0",
"description": "JavaScript API clients for ULMS platform",
"keywords": [],
"homepage": "https://github.com/foxford/ulms-api-clients-js#readme",
Expand Down
18 changes: 12 additions & 6 deletions src/basic-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const parseParameter = (key, value) => {
class BasicClient {
constructor(baseUrl, httpClient, tokenProvider) {
this.baseUrl = baseUrl
this.customHeaders = {}
this.httpClient = httpClient
this.tokenProvider = tokenProvider
this.labels = {}
Expand All @@ -51,14 +52,19 @@ class BasicClient {
return `${this.baseUrl}${endpoint}`
}

static headers(token, labels = {}) {
static headers(token, labels = {}, headers = {}) {
return {
...headers,
authorization: `Bearer ${token}`,
'content-type': 'application/json',
...labels,
}
}

setHeaders(headers) {
this.customHeaders = headers
}

setLabels(labels) {
const { app_audience, app_label, app_version, scope } = labels // eslint-disable-line camelcase

Expand All @@ -78,7 +84,7 @@ class BasicClient {
const token = await this.tokenProvider.getToken()
const headers = {
...options.headers,
...BasicClient.headers(token, this.labels),
...BasicClient.headers(token, this.labels, this.customHeaders),
}
const requestOptions = { ...options, headers }

Expand All @@ -89,7 +95,7 @@ class BasicClient {
const token = await this.tokenProvider.getToken()
const headers = {
...options.headers,
...BasicClient.headers(token, this.labels),
...BasicClient.headers(token, this.labels, this.customHeaders),
}
const requestOptions = { ...options, headers }

Expand All @@ -100,7 +106,7 @@ class BasicClient {
const token = await this.tokenProvider.getToken()
const headers = {
...options.headers,
...BasicClient.headers(token, this.labels),
...BasicClient.headers(token, this.labels, this.customHeaders),
}
const requestOptions = { ...options, headers }

Expand All @@ -111,7 +117,7 @@ class BasicClient {
const token = await this.tokenProvider.getToken()
const headers = {
...options.headers,
...BasicClient.headers(token, this.labels),
...BasicClient.headers(token, this.labels, this.customHeaders),
}
const requestOptions = { ...options, headers }

Expand All @@ -122,7 +128,7 @@ class BasicClient {
const token = await this.tokenProvider.getToken()
const headers = {
...options.headers,
...BasicClient.headers(token, this.labels),
...BasicClient.headers(token, this.labels, this.customHeaders),
}
const requestOptions = { ...options, headers }

Expand Down
15 changes: 4 additions & 11 deletions src/http-conference.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,10 @@ class HTTPConference extends BasicClient {
/**
* Enter room
* @param roomId
* @param agentLabel
* @returns {Promise}
*/
enterRoom(roomId, agentLabel) {
const payload = { agent_label: agentLabel }

return this.post(this.url(`/rooms/${roomId}/enter`), payload)
enterRoom(roomId) {
return this.post(this.url(`/rooms/${roomId}/enter`))
}

/**
Expand Down Expand Up @@ -159,15 +156,13 @@ class HTTPConference extends BasicClient {
/**
* Connect to RTC
* @param {String} rtcId
* @param {String} agentLabel
* @param {Object} optionParameters
* @param {String} optionParameters.intent - Intent to connect to RTC ('read' or 'write')
* @returns {Promise}
*/
connectRtc(rtcId, agentLabel, optionParameters = {}) {
connectRtc(rtcId, optionParameters = {}) {
const { intent = HTTPConference.intents.INTENT_READ } = optionParameters
const payload = {
agent_label: agentLabel,
intent,
}

Expand All @@ -189,12 +184,10 @@ class HTTPConference extends BasicClient {
* @param {String} handleId
* @param {Object|Object[]} jsep
* @param {String} label
* @param {String} agentLabel
* @returns {Promise}
*/
createRtcSignal(handleId, jsep, label, agentLabel) {
createRtcSignal(handleId, jsep, label) {
const payload = {
agent_label: agentLabel,
jsep,
handle_id: handleId,
label,
Expand Down

0 comments on commit 6940d75

Please sign in to comment.