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 all commits
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
44 changes: 29 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.hostResolver = null

this.socketConfig = null

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

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

if (!isUndefined(config.appId)) {
if (!isString(config.appId)) {
throw new Error('"appId" must be String.')
Expand Down Expand Up @@ -79,18 +86,33 @@ 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.hostResolver) {
host = await this.hostResolver()
} 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 +126,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
}
}