Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API-3 - Extend API Info response #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 30 additions & 15 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class RTConfig {
this.debugMode = false
this.connectQuery = {}
this.socketConfigTransform = null
this.getAppInfo = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appInfo is not a good name for that, since the appInfo is more related to backendless app API not for RT Client

what about hostResolver?


this.socketConfig = null

Expand All @@ -25,6 +26,12 @@ export default class RTConfig {
return
}

if (!isUndefined(config.getAppInfo)) {
if (isFunction(config.getAppInfo)) {
this.getAppInfo = config.getAppInfo
}
}

if (!isUndefined(config.appId)) {
if (!isString(config.appId)) {
throw new Error('"appId" must be String.')
Expand Down Expand Up @@ -79,18 +86,34 @@ export default class RTConfig {
return this.connectQuery
}

async prepare() {
if (!isString(this.lookupPath)) {
throw new Error('lookupPath must be String')
getSocketConfig() {
return this.socketConfig
}

async getHost() {
let host

if (this.getAppInfo) {
const { rtURL } = await this.getAppInfo()
host = rtURL
} else {
host = await Request.get(this.lookupPath).set(this.lookupHeaders)
}

const host = await Request.get(this.lookupPath).set(this.lookupHeaders)
return host
}

async prepare() {
const query = this.getConnectQuery()
const host = await this.getHost()

if (!host) {
throw new Error('Host is not defined')
}

const url = this.appId ? `${ host }/${ this.appId }` : host
const path = this.appId ? `/${ this.appId }` : undefined

const query = this.getConnectQuery()

this.socketConfig = {
host,
url,
Expand All @@ -104,16 +127,8 @@ export default class RTConfig {
}

if (this.socketConfigTransform) {
const socketConfig = await this.socketConfigTransform(this.socketConfig)

if (socketConfig) {
this.socketConfig = socketConfig
}
this.socketConfig = await this.socketConfigTransform(this.socketConfig) || this.socketConfig
}
}

getSocketConfig() {
return this.socketConfig
}
}