import { Options, ExecuteType, CallType, Cloudstorage, } from "./types"; import { ProviderConstructor, Provider } from "../providers/provider"; import { CloudStorage } from "../storage/cloudstorage"; import { RayconnectCore } from "./core"; import { Services } from "./services"; import { QueryService } from "../services/query"; export class RayconnectBase extends RayconnectCore { public app: any; protected loginData = { username: "", password: "" }; protected middlewares: Function[] = []; CloudStorage: Cloudstorage; protected services: Services constructor( options: Options, token: any, config: any, provider: ProviderConstructor, ) { super(options, token, config, provider) this.services = { query: new QueryService() } // compatible with old api this.CloudStorage = new CloudStorage( this.CloudStorageservice, this.CloudStorageservice.Keys ); this.socket = this.Connect(); this.OnConnect(async () => { this.realTime = true; // await this.getAccess(); }); this.App(); this.AutedEvent(); this.DisOnConnect(() => { this.authed = false; this.realTime = false; // this.user = null }); } private AutedEvent() { this.socket.on("authed", (msg: any) => { const data = msg; this.authed = true; Provider.isAuthed = true; // stacked events for (const element of Provider.events_stack) { this.socket.emit(element.key, element.value) } Provider.events_stack = [] this.user = data.data; }); } private App() { this.socket.on("app_data", (data: any) => { this.app = data; }); } DisOnConnect(callback: { (): void; (): void }) { this.socket.on("disconnect", () => { callback(); }); } protected makeExec(param: CallType, plugin?: string) { param = this.defaultUser(param); const exec: ExecuteType = { scope: param.scope, uniqueID: param.user, TokenID: param.token, address: param.address, info: { method: param.method, app_id:param.app, data: param.data }, }; if (plugin) exec.info.plugin = plugin return exec; } protected defaultUser(param: CallType) { if (!param.user && !param.token) { param.user = this.ops.appID + "_admin_system"; param.token = "*"; } if (!param.user) { param.user = "*"; } if (!param.token) { param.token = "*"; } return param; } protected getMessageID() { const id = this.message_id++; return id.toString(); } protected Dpack(msg: any) { return msg; } public async checkCache(event: string | symbol, listner: (...args: any[]) => void) { try { const db = await this.openDB(); } catch (error) { } } public readData(event: string | symbol, listner: (...args: any[]) => void) { const ev: string = event.toString(); /*if(ev.startsWith('exec_gram_')){ return this.checkCache(event,listner); } */ this.socket.once(event, (data: any) => { listner(data) }); } }