internal prefix private props.

This commit is contained in:
Miroslav Šedivý 2021-04-24 21:06:42 +02:00
parent bf7a3b9163
commit edc4ea427d
2 changed files with 28 additions and 28 deletions

View File

@ -1,33 +1,33 @@
import * as Api from '../api' import * as Api from '../api'
export class NekoApi { export class NekoApi {
api_configuration = new Api.Configuration({ private _config = new Api.Configuration({
basePath: location.href.replace(/\/+$/, ''), basePath: location.href.replace(/\/+$/, ''),
baseOptions: { withCredentials: true }, baseOptions: { withCredentials: true },
}) })
public setUrl(url: string) { public setUrl(url: string) {
this.api_configuration.basePath = url.replace(/\/+$/, '') this._config.basePath = url.replace(/\/+$/, '')
} }
public setToken(token: string) { public setToken(token: string) {
this.api_configuration.accessToken = token this._config.accessToken = token
} }
get url(): string { get url(): string {
return this.api_configuration.basePath || location.href.replace(/\/+$/, '') return this._config.basePath || location.href.replace(/\/+$/, '')
} }
get session(): SessionApi { get session(): SessionApi {
return new Api.SessionApi(this.api_configuration) return new Api.SessionApi(this._config)
} }
get room(): RoomApi { get room(): RoomApi {
return new Api.RoomApi(this.api_configuration) return new Api.RoomApi(this._config)
} }
get members(): MembersApi { get members(): MembersApi {
return new Api.MembersApi(this.api_configuration) return new Api.MembersApi(this._config)
} }
} }

View File

@ -42,18 +42,18 @@ export interface NekoEvents {
} }
export class NekoMessages extends EventEmitter<NekoEvents> { export class NekoMessages extends EventEmitter<NekoEvents> {
private websocket: NekoWebSocket private _websocket: NekoWebSocket
private state: NekoState private _state: NekoState
private _log: Logger private _log: Logger
constructor(websocket: NekoWebSocket, state: NekoState) { constructor(websocket: NekoWebSocket, state: NekoState) {
super() super()
this._log = new Logger('messages') this._log = new Logger('messages')
this.state = state this._state = state
this.websocket = websocket this._websocket = websocket
this.websocket.on('message', async (event: string, payload: any) => { this._websocket.on('message', async (event: string, payload: any) => {
// @ts-ignore // @ts-ignore
if (typeof this[event] === 'function') { if (typeof this[event] === 'function') {
// @ts-ignore // @ts-ignore
@ -70,8 +70,8 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
protected [EVENT.SYSTEM_INIT](conf: message.SystemInit) { protected [EVENT.SYSTEM_INIT](conf: message.SystemInit) {
this._log.debug('EVENT.SYSTEM_INIT') this._log.debug('EVENT.SYSTEM_INIT')
Vue.set(this.state, 'session_id', conf.session_id) Vue.set(this._state, 'session_id', conf.session_id)
Vue.set(this.state.control, 'implicit_hosting', conf.implicit_hosting) Vue.set(this._state.control, 'implicit_hosting', conf.implicit_hosting)
for (const id in conf.sessions) { for (const id in conf.sessions) {
this[EVENT.SESSION_CREATED](conf.sessions[id]) this[EVENT.SESSION_CREATED](conf.sessions[id])
@ -93,14 +93,14 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
return b.width - a.width return b.width - a.width
}) })
Vue.set(this.state.screen, 'configurations', list) Vue.set(this._state.screen, 'configurations', list)
this[EVENT.BORADCAST_STATUS](broadcast_status) this[EVENT.BORADCAST_STATUS](broadcast_status)
} }
protected [EVENT.SYSTEM_DISCONNECT]({ message }: message.SystemDisconnect) { protected [EVENT.SYSTEM_DISCONNECT]({ message }: message.SystemDisconnect) {
this._log.debug('EVENT.SYSTEM_DISCONNECT') this._log.debug('EVENT.SYSTEM_DISCONNECT')
this.websocket.disconnect(new Error(message)) this._websocket.disconnect(new Error(message))
this.emit('connection.disconnect', message) this.emit('connection.disconnect', message)
} }
@ -110,8 +110,8 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
protected [EVENT.SIGNAL_PROVIDE]({ event, sdp, video, videos }: message.SignalProvide) { protected [EVENT.SIGNAL_PROVIDE]({ event, sdp, video, videos }: message.SignalProvide) {
this._log.debug('EVENT.SIGNAL_PROVIDE') this._log.debug('EVENT.SIGNAL_PROVIDE')
Vue.set(this.state.connection.webrtc, 'video', video) Vue.set(this._state.connection.webrtc, 'video', video)
Vue.set(this.state.connection.webrtc, 'videos', videos) Vue.set(this._state.connection.webrtc, 'videos', videos)
// TODO: Handle. // TODO: Handle.
this.emit('connection.webrtc.sdp', 'remote', sdp) this.emit('connection.webrtc.sdp', 'remote', sdp)
} }
@ -124,7 +124,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
protected [EVENT.SIGNAL_VIDEO]({ event, video }: message.SignalVideo) { protected [EVENT.SIGNAL_VIDEO]({ event, video }: message.SignalVideo) {
this._log.debug('EVENT.SIGNAL_VIDEO') this._log.debug('EVENT.SIGNAL_VIDEO')
Vue.set(this.state.connection.webrtc, 'video', video) Vue.set(this._state.connection.webrtc, 'video', video)
} }
///////////////////////////// /////////////////////////////
@ -133,25 +133,25 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
protected [EVENT.SESSION_CREATED]({ id, ...data }: message.SessionData) { protected [EVENT.SESSION_CREATED]({ id, ...data }: message.SessionData) {
this._log.debug('EVENT.SESSION_CREATED', id) this._log.debug('EVENT.SESSION_CREATED', id)
Vue.set(this.state.sessions, id, data) Vue.set(this._state.sessions, id, data)
this.emit('session.created', id) this.emit('session.created', id)
} }
protected [EVENT.SESSION_DELETED]({ id }: message.SessionID) { protected [EVENT.SESSION_DELETED]({ id }: message.SessionID) {
this._log.debug('EVENT.SESSION_DELETED', id) this._log.debug('EVENT.SESSION_DELETED', id)
Vue.delete(this.state.sessions, id) Vue.delete(this._state.sessions, id)
this.emit('session.deleted', id) this.emit('session.deleted', id)
} }
protected [EVENT.SESSION_PROFILE]({ id, ...profile }: message.MemberProfile) { protected [EVENT.SESSION_PROFILE]({ id, ...profile }: message.MemberProfile) {
this._log.debug('EVENT.SESSION_PROFILE', id) this._log.debug('EVENT.SESSION_PROFILE', id)
Vue.set(this.state.sessions[id], 'profile', profile) Vue.set(this._state.sessions[id], 'profile', profile)
this.emit('session.updated', id) this.emit('session.updated', id)
} }
protected [EVENT.SESSION_STATE]({ id, ...state }: message.SessionState) { protected [EVENT.SESSION_STATE]({ id, ...state }: message.SessionState) {
this._log.debug('EVENT.SESSION_STATE', id) this._log.debug('EVENT.SESSION_STATE', id)
Vue.set(this.state.sessions[id], 'state', state) Vue.set(this._state.sessions[id], 'state', state)
this.emit('session.updated', id) this.emit('session.updated', id)
} }
@ -163,9 +163,9 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
this._log.debug('EVENT.CONTROL_HOST') this._log.debug('EVENT.CONTROL_HOST')
if (has_host && host_id) { if (has_host && host_id) {
Vue.set(this.state.control, 'host_id', host_id) Vue.set(this._state.control, 'host_id', host_id)
} else { } else {
Vue.set(this.state.control, 'host_id', null) Vue.set(this._state.control, 'host_id', null)
} }
this.emit('room.control.host', has_host, host_id) this.emit('room.control.host', has_host, host_id)
@ -177,7 +177,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
protected [EVENT.SCREEN_UPDATED]({ width, height, rate }: message.ScreenSize) { protected [EVENT.SCREEN_UPDATED]({ width, height, rate }: message.ScreenSize) {
this._log.debug('EVENT.SCREEN_UPDATED') this._log.debug('EVENT.SCREEN_UPDATED')
Vue.set(this.state.screen, 'size', { width, height, rate }) Vue.set(this._state.screen, 'size', { width, height, rate })
this.emit('room.screen.updated', width, height, rate) this.emit('room.screen.updated', width, height, rate)
} }
@ -187,7 +187,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
protected [EVENT.CLIPBOARD_UPDATED]({ text }: message.ClipboardData) { protected [EVENT.CLIPBOARD_UPDATED]({ text }: message.ClipboardData) {
this._log.debug('EVENT.CLIPBOARD_UPDATED') this._log.debug('EVENT.CLIPBOARD_UPDATED')
Vue.set(this.state.control, 'clipboard', { text }) Vue.set(this._state.control, 'clipboard', { text })
this.emit('room.clipboard.updated', text) this.emit('room.clipboard.updated', text)
} }
@ -222,7 +222,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
protected [EVENT.FILE_CHOOSER_DIALOG_OPENED]({ id }: message.SessionID) { protected [EVENT.FILE_CHOOSER_DIALOG_OPENED]({ id }: message.SessionID) {
this._log.debug('EVENT.FILE_CHOOSER_DIALOG_OPENED') this._log.debug('EVENT.FILE_CHOOSER_DIALOG_OPENED')
if (id == this.state.session_id) { if (id == this._state.session_id) {
this.emit('upload.dialog.requested') this.emit('upload.dialog.requested')
} else { } else {
this.emit('upload.dialog.overlay', id) this.emit('upload.dialog.overlay', id)