Skip to content

Commit

Permalink
ULMS-2892 Added ULMS client (cloned Dispatcher)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkonst committed Mar 7, 2024
1 parent ac76c3e commit 2444ddd
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 3 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": "7.0.0",
"version": "7.1.0",
"description": "JavaScript API clients for ULMS platform",
"keywords": [],
"homepage": "https://github.com/foxford/ulms-api-clients-js#readme",
Expand Down
3 changes: 3 additions & 0 deletions src/dispatcher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import BasicClient from './basic-client'

/**
* @deprecated Use ULMS client instead of Dispatcher client
*/
class Dispatcher extends BasicClient {
/**
* Scope kind enum
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export { default as PresenceWS } from './presence-ws'
export { default as Storage } from './storage'
export { default as Tenant } from './tenant'
export { default as TokenProvider } from './token-provider'
export { default as ULMS } from './ulms'
export { default as VisibilityStateMonitor } from './visibility-state-monitor'
193 changes: 193 additions & 0 deletions src/ulms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
import BasicClient from './basic-client'

class ULMS extends BasicClient {
/**
* Scope kind enum
* @returns {{CHAT: string, MINIGROUP: string, P2P: string, WEBINAR: string}}
*/
static get kind() {
return {
CHAT: 'chats',
MINIGROUP: 'minigroups',
P2P: 'p2p',
WEBINAR: 'webinars',
}
}

/**
* Scope status enum
* @returns {{REAL_TIME: string, CLOSED: string, FINISHED: string, ADJUSTED: string, TRANSCODED: string}}
*/
static get scopeStatus() {
return {
REAL_TIME: 'real-time',
CLOSED: 'closed',
FINISHED: 'finished',
ADJUSTED: 'adjusted',
TRANSCODED: 'transcoded',
}
}

/**
* Class properties enum
* @returns {{IS_ADULT: string, HAS_USER_ACCESS_TO_BOARD: string}}
*/
static get classKeys() {
return {
IS_ADULT: 'is_adult',
HAS_USER_ACCESS_TO_BOARD: 'has_user_access_to_board',
EMOTIONS: 'emotions',
}
}

/**
* Account properties enum
* @returns {{ONBOARDING: string}}
*/
static get accountKeys() {
return {
LAST_SEEN_MESSAGE_ID_BY_ROOMS: 'last_seen_message_id_by_rooms',
ONBOARDING: 'onboarding',
}
}

/**
* Bans media stream and collaboration for user
* @param {{ accountId: string, ban: boolean, classId: string }}
* @returns {Promise}
*/
banUser({ accountId, ban, classId }) {
return this.get(
`${this.baseUrl}/account/${accountId}/ban/${classId}` // get last ban operation id for user
// eslint-disable-next-line camelcase
).then(({ last_seen_op_id }) =>
this.post(`${this.baseUrl}/account/${accountId}/ban`, {
ban,
class_id: classId,
// eslint-disable-next-line camelcase
last_seen_op_id,
})
)
}

/**
* Commit edition by scope
* @param {string} audience
* @param {string} scope
* @param {string} editionId
* @returns {Promise}
*/
commitEdition(audience, scope, editionId) {
return this.post(
`${this.baseUrl}/audiences/${audience}/classes/${scope}/editions/${editionId}`
)
}

/**
* Fetch token data for NATS
* @param {string} classroomId
* @returns {Promise}
*/
fetchTokenData(classroomId) {
return this.post(`${this.baseUrl}/classrooms/${classroomId}/tokens`)
}

/**
* Read ulms scope
* @param {string} kind
* @param {string} audience
* @param {string} scope
* @param {object} options
* @returns {Promise}
*/
readScope(kind, audience, scope, options) {
return this.get(
this.url(`/audiences/${audience}/${kind}/${scope}`, options)
)
}

/**
* Read class property
* @param {string} kind
* @param {string} classId
* @param {string} propertyId
* @returns {Promise}
*/
readClassProperty(kind, classId, propertyId) {
return this.get(
`${this.baseUrl}/${kind}/${classId}/properties/${propertyId}`
)
}

/**
* Update class property
* @param {string} kind
* @param {string} classId
* @param {string} propertyId
* @param {object} data
* @returns {Promise}
*/
updateClassProperty(kind, classId, propertyId, data) {
return this.put(
`${this.baseUrl}/${kind}/${classId}/properties/${propertyId}`,
data
)
}

/**
* Read account property
* @param {string} propertyId
* @returns {Promise}
*/
readAccountProperty(propertyId) {
return this.get(`${this.baseUrl}/account/properties/${propertyId}`)
}

/**
* Update account property
* @param {string} propertyId
* @param {object} data
* @returns {Promise}
*/
updateAccountProperty(propertyId, data) {
return this.put(`${this.baseUrl}/account/properties/${propertyId}`, data)
}

/**
* Update ulms scope
* @param {string} kind
* @param {string} audience
* @param {string} scope
* @param {object} data
* @returns {Promise}
*/
updateScope(kind, audience, scope, data) {
return this.put(
`${this.baseUrl}/audiences/${audience}/${kind}/${scope}`,
data
)
}

/**
* Update position timestamp
* @param {string} kind
* @param {string} classId
* @param {number} position
* @returns {Promise}
*/
updatePosition(kind, classId, position) {
const controller = new AbortController()
const { signal } = controller
const timeoutId = setTimeout(() => controller.abort(), 10 * 1000)

return this.post(
`${this.baseUrl}/${kind}/${classId}/timestamps`,
{ position },
{ signal }
).finally(() => {
clearTimeout(timeoutId)
})
}
}

export default ULMS

0 comments on commit 2444ddd

Please sign in to comment.