use new evite methods

This commit is contained in:
SrGooglo 2023-08-02 20:38:41 +00:00
parent aa8e0864cc
commit 2057b3473d
16 changed files with 78 additions and 69 deletions

View File

@ -8,9 +8,11 @@ import useRequest from "comty.js/hooks/useRequest"
import { reconnectWebsockets } from "comty.js"
export default class APICore extends Core {
static refName = "api"
static namespace = "api"
static bgColor = "coral"
static textColor = "black"
instance = null
public = {
@ -37,7 +39,7 @@ export default class APICore extends Core {
createPingIntervals() {
Object.keys(this.instance.wsInstances).forEach((instance) => {
console.debug(`[API] Creating ping interval for ${instance}`)
this.console.debug(`[API] Creating ping interval for ${instance}`)
if (this.instance.wsInstances[instance].pingInterval) {
clearInterval(this.instance.wsInstances[instance].pingInterval)
@ -45,14 +47,14 @@ export default class APICore extends Core {
this.instance.wsInstances[instance].pingInterval = setInterval(() => {
if (this.instance.wsInstances[instance].pendingPingTry && this.instance.wsInstances[instance].pendingPingTry > 3) {
console.debug(`[API] Ping timeout for ${instance}`)
this.console.debug(`[API] Ping timeout for ${instance}`)
return clearInterval(this.instance.wsInstances[instance].pingInterval)
}
const timeStart = Date.now()
//console.debug(`[API] Ping ${instance}`, this.instance.wsInstances[instance].pendingPingTry)
//this.console.debug(`[API] Ping ${instance}`, this.instance.wsInstances[instance].pendingPingTry)
this.instance.wsInstances[instance].emit("ping", () => {
this.instance.wsInstances[instance].latency = Date.now() - timeStart
@ -92,7 +94,7 @@ export default class APICore extends Core {
method: "GET",
url: "/ping",
}).catch((error) => {
console.error("[API] Ping error", error)
this.console.error("[API] Ping error", error)
throw new Error(`
Could not connect to the API.
@ -100,7 +102,7 @@ export default class APICore extends Core {
`)
})
console.debug("[API] Attached to", this.instance)
this.console.debug("[API] Attached to", this.instance)
this.createPingIntervals()

View File

@ -7,7 +7,6 @@ import ContextMenu from "./components/contextMenu"
import InternalContexts from "schemas/menu-contexts"
export default class ContextMenuCore extends Core {
static refName = "contextMenu"
static namespace = "contextMenu"
public = {
@ -26,7 +25,7 @@ export default class ContextMenuCore extends Core {
async onInitialize() {
if (app.isMobile) {
console.warn("Context menu is not available on mobile")
this.console.warn("Context menu is not available on mobile")
return false
}
@ -125,7 +124,7 @@ export default class ContextMenuCore extends Core {
const items = await this.generateItems(component)
if (!items) {
console.warn("No context menu items found, aborting")
this.console.warn("No context menu items found, aborting")
return false
}

View File

@ -9,8 +9,8 @@ const vibrationPatterns = {
}
export default class HapticsCore extends Core {
static refName = "haptics"
static namespace = "haptics"
static dependencies = [
"settings"
]

View File

@ -15,7 +15,7 @@ export function extractLocaleFromPath(path = "") {
const messageImports = import.meta.glob("schemas/translations/*.json")
export default class I18nCore extends Core {
static refName = "i18n"
static namespace = "i18n"
onEvents = {
"changeLanguage": (locale) => {
@ -67,7 +67,7 @@ export default class I18nCore extends Core {
i18n.changeLanguage(locale)
}
} catch (error) {
console.error(error)
this.console.error(error)
}
}
}

View File

@ -77,8 +77,6 @@ function parseNdefMessage(ndefMessage) {
}
export default class NFC extends Core {
static refName = "NFC"
static namespace = "nfc"
isNativeMode = false
@ -141,7 +139,7 @@ export default class NFC extends Core {
this.public.scanning = false
this.public.incompatible = true
console.error(error)
this.console.error(error)
}
}
@ -153,7 +151,7 @@ export default class NFC extends Core {
}
handleRead(tag) {
console.debug(`[NFC] READ >`, tag)
this.console.debug(`[NFC] READ >`, tag)
// send to subscribers
this.subscribers.forEach((subscriber) => {
@ -173,7 +171,7 @@ export default class NFC extends Core {
}
handleNativeRead(tag) {
console.debug(`[NFC] NATIVE READ >`, tag)
this.console.debug(`[NFC] NATIVE READ >`, tag)
tag.serialNumber = resolveSerialNumber(tag)
@ -230,7 +228,7 @@ export default class NFC extends Core {
}
async writeNdef(payload, options) {
console.debug(`[NFC] WRITE >`, payload)
this.console.debug(`[NFC] WRITE >`, payload)
if (!this.isNativeMode) {
return this.instance.write(payload, options)

View File

@ -13,7 +13,7 @@ const NotfTypeToAudio = {
}
export default class NotificationCore extends Core {
static refName = "notifications"
static namespace = "notifications"
onEvents = {
"changeNotificationsSoundVolume": (value) => {

View File

@ -4,8 +4,8 @@ import UserModel from "models/user"
import SessionModel from "models/session"
export default class PermissionsCore extends Core {
static refName = "permissions"
static namespace = "permissions"
static dependencies = ["api"]
public = {

View File

@ -151,7 +151,7 @@ class ChunkedUpload {
.catch((err) => {
if (this.paused || this.offline) return
console.error(err)
this.console.error(err)
// this type of error can happen after network disconnection on CORS setup
this.manageRetries()
@ -208,7 +208,7 @@ export default class RemoteStorage extends Core {
})
uploader.on("error", ({ message }) => {
console.error("[Uploader] Error", message)
this.console.error("[Uploader] Error", message)
if (typeof onError === "function") {
onError(file, message)
@ -219,7 +219,7 @@ export default class RemoteStorage extends Core {
})
uploader.on("progress", ({ percentProgress }) => {
//console.debug(`[Uploader] Progress: ${percentProgress}%`)
//this.console.debug(`[Uploader] Progress: ${percentProgress}%`)
if (typeof onProgress === "function") {
onProgress(file, percentProgress)
@ -227,7 +227,7 @@ export default class RemoteStorage extends Core {
})
uploader.on("finish", (data) => {
console.debug("[Uploader] Finish", data)
this.console.debug("[Uploader] Finish", data)
if (typeof onFinish === "function") {
onFinish(file, data)

View File

@ -4,7 +4,6 @@ import remotes from "comty.js/remotes"
import SessionModel from "comty.js/models/session"
export default class RoomsController extends Core {
static refName = "rooms"
static namespace = "rooms"
connectedRooms = []

View File

@ -4,8 +4,6 @@ import defaultSettings from "schemas/defaultSettings.json"
import { Observable } from "rxjs"
export default class SettingsCore extends Core {
static refName = "settings"
static namespace = "settings"
static storeKey = "app_settings"

View File

@ -1,7 +1,6 @@
import Core from "evite/src/core"
export default class ShortcutsCore extends Core {
static refName = "shortcuts"
static namespace = "shortcuts"
public = {
@ -81,7 +80,7 @@ export default class ShortcutsCore extends Core {
const register = this.shortcutsRegister.find((handler) => handler.id === id)
if (!register) {
console.warn(`Shortcut with id "${id}" not found`)
this.console.warn(`Shortcut with id "${id}" not found`)
return false
}

View File

@ -5,8 +5,6 @@ import axios from "axios"
import store from "store"
export default class SoundCore extends Core {
static refName = "sound"
static namespace = "sound"
soundsPool = {}
@ -20,7 +18,7 @@ export default class SoundCore extends Core {
this.play(audio_id)
}
} catch (error) {
console.error(error)
this.console.error(error)
}
}.bind(this)
}
@ -49,17 +47,17 @@ export default class SoundCore extends Core {
soundpack = data
} else {
console.error(`Soundpack [${storedCustomSoundpack}] is not a valid url.`)
this.console.error(`Soundpack [${storedCustomSoundpack}] is not a valid url.`)
return false
}
}
if (typeof soundpack.sounds !== "object") {
console.error(`Soundpack [${soundpack.id}] is not a valid soundpack.`)
this.console.error(`Soundpack [${soundpack.id}] is not a valid soundpack.`)
return false
}
console.log(`Loading soundpack [${soundpack.id} | ${soundpack.name}] by ${soundpack.author} (${soundpack.version})`)
this.console.log(`Loading soundpack [${soundpack.id} | ${soundpack.name}] by ${soundpack.author} (${soundpack.version})`)
for (const [name, path] of Object.entries(soundpack.sounds)) {
this.soundsPool[name] = new Howl({
@ -93,7 +91,7 @@ export default class SoundCore extends Core {
const audioInstance = this.soundsPool[name]
if (!audioInstance) {
console.error(`Sound [${name}] not found or is not available.`)
this.console.error(`Sound [${name}] not found or is not available.`)
return false
}

View File

@ -1,6 +1,4 @@
import React from "react"
import ReactDOM from "react-dom"
import SVG from "react-inlinesvg"
import Core from "evite/src/core"
import config from "config"
@ -66,11 +64,10 @@ export class ThemeProvider extends React.Component {
}
export default class StyleCore extends Core {
static refName = "style"
static dependencies = ["settings"]
static namespace = "style"
static dependencies = ["settings"]
static themeManifestStorageKey = "theme"
static modificationStorageKey = "themeModifications"
@ -140,7 +137,7 @@ export default class StyleCore extends Core {
// handle auto prefered color scheme
window.matchMedia("(prefers-color-scheme: light)").addListener(() => {
console.log(`[THEME] Auto color scheme changed`)
this.console.log(`[THEME] Auto color scheme changed`)
this.applyVariant(StyleCore.variant)
})
@ -250,7 +247,7 @@ export default class StyleCore extends Core {
const values = this.public.theme.variants[variant]
if (!values) {
console.error(`Variant [${variant}] not found`)
this.console.error(`Variant [${variant}] not found`)
return false
}

View File

@ -7,6 +7,8 @@ import SyncRoomCard from "components/SyncRoomCard"
import Image from "components/Image"
import { openModal as OpenUserSelectorModal } from "components/UserSelector"
import SyncModel from "comty.js/models/sync"
// TODO: Sync current state with server
class MusicSyncSubCore {
constructor(ctx) {
@ -40,7 +42,7 @@ class MusicSyncSubCore {
hubEvents = {
"invite:received": (data) => {
console.log("invite:received", data)
this.console.log("invite:received", data)
app.notification.new({
title: "Sync",
@ -60,7 +62,7 @@ class MusicSyncSubCore {
})
},
"room:joined": (data) => {
console.log("room:joined", data)
this.console.log("room:joined", data)
this.currentRoomData = data
@ -72,7 +74,7 @@ class MusicSyncSubCore {
this.eventBus.emit("room:joined", data)
},
"room:left": (data) => {
console.log("room:left", data)
this.console.log("room:left", data)
this.dettachCard()
@ -106,7 +108,7 @@ class MusicSyncSubCore {
this.eventBus.emit("room:user:left", data)
},
"room:current-data": (data) => {
console.log("room:current-data", data)
this.console.log("room:current-data", data)
this.currentRoomData = data
this.eventBus.emit("room:current-data", data)
@ -167,7 +169,7 @@ class MusicSyncSubCore {
}
},
"room:moderation:kicked": (data) => {
console.log("room:moderation:kicked", data)
this.console.log("room:moderation:kicked", data)
this.dettachCard()
@ -208,7 +210,7 @@ class MusicSyncSubCore {
let state = app.cores.player.currentState()
console.log("state", state)
this.console.log("state", state)
this.musicWs.emit("music:state:update", {
...state,
@ -235,7 +237,7 @@ class MusicSyncSubCore {
}
if (!app.layout.floatingStack) {
console.error("Floating stack not found")
this.console.error("Floating stack not found")
return false
}
@ -248,7 +250,7 @@ class MusicSyncSubCore {
}
if (!app.layout.floatingStack) {
console.error("Floating stack not found")
this.console.error("Floating stack not found")
return false
}
@ -259,7 +261,7 @@ class MusicSyncSubCore {
joinRoom(roomId, options) {
if (this.currentRoomData) {
console.warn(`Already joined room ${this.currentRoomData}`)
this.console.warn(`Already joined room ${this.currentRoomData}`)
return false
}
@ -280,7 +282,7 @@ class MusicSyncSubCore {
this.dettachCard()
if (!roomId && !this.currentRoomData) {
console.warn(`Not joined any room`)
this.console.warn(`Not joined any room`)
return false
}
@ -307,7 +309,7 @@ class MusicSyncSubCore {
inviteToUser(userId) {
if (!this.currentRoomData) {
console.warn(`Not joined any room`)
this.console.warn(`Not joined any room`)
return false
}
@ -320,7 +322,7 @@ class MusicSyncSubCore {
createSyncRoom() {
if (this.currentRoomData) {
console.warn(`Already joined room ${this.currentRoomData}`)
this.console.warn(`Already joined room ${this.currentRoomData}`)
return false
}
@ -336,14 +338,14 @@ class MusicSyncSubCore {
//open invite modal
OpenUserSelectorModal({
onFinished: (selected_ids) => {
console.log("selected_ids", selected_ids)
this.console.log("selected_ids", selected_ids)
}
})
}
kickUser(userId) {
if (!this.currentRoomData) {
console.warn(`Not joined any room`)
this.console.warn(`Not joined any room`)
return false
}
@ -356,7 +358,7 @@ class MusicSyncSubCore {
transferOwner(userId) {
if (!this.currentRoomData) {
console.warn(`Not joined any room`)
this.console.warn(`Not joined any room`)
return false
}
@ -369,11 +371,16 @@ class MusicSyncSubCore {
}
export default class SyncCore extends Core {
static refName = "sync"
static namespace = "sync"
static dependencies = ["api", "player"]
public = {}
activeLinkedServices = {}
public = {
getActiveLinkedServices: function () {
return this.activeLinkedServices
}.bind(this),
}
async onInitialize() {
const subCores = [
@ -390,8 +397,20 @@ export default class SyncCore extends Core {
this.public[subCore.constructor.namespace] = subCore.public
}
} catch (error) {
console.error(error)
this.console.error(error)
}
}
}
async initializeAfterCoresInit() {
const activeServices = await SyncModel.getLinkedServices().catch((error) => {
this.console.error(error)
return null
})
if (activeServices) {
this.console.log(`Active services`, activeServices)
this.activeLinkedServices = activeServices
}
}
}

View File

@ -21,13 +21,13 @@ export default class TasksQueue extends Core {
processTasks() {
if (this.runningTasksIds.length >= TasksQueue.maxRunningTasks ?? 1) {
console.log("We are already running the maximum number of tasks")
this.console.log("We are already running the maximum number of tasks")
return false
}
// check if there are new tasks in the queue and move them to the tasks array with the maximum number of tasks can be run
if (this.taskQueue.length === 0) {
console.log("No tasks in the queue")
this.console.log("No tasks in the queue")
return false
}
@ -67,7 +67,7 @@ export default class TasksQueue extends Core {
this.processTasks()
})
.catch((error) => {
console.error(error)
this.console.error(error)
this.processTasks()
})
}

View File

@ -29,7 +29,7 @@ export default class WidgetsCore extends Core {
store.set(WidgetsCore.storeKey, [])
}
} catch (error) {
console.error(error)
this.console.error(error)
}
}
@ -40,7 +40,7 @@ export default class WidgetsCore extends Core {
isInstalled(widget_id) {
const widgets = this.getInstalled()
console.log(widgets)
this.console.log(widgets)
const widget = widgets.find((widget) => widget._id === widget_id)
@ -52,14 +52,14 @@ export default class WidgetsCore extends Core {
throw new Error("Widget id must be a string.")
}
console.debug(`🧩 Installing widget with id [${widget_id}]`)
this.console.debug(`🧩 Installing widget with id [${widget_id}]`)
// get manifest
let manifest = await WidgetsCore.apiInstance({
method: "GET",
url: `/widgets/${widget_id}/manifest`,
}).catch((error) => {
console.error(error)
this.console.error(error)
app.message.error("Cannot install widget.")
return false
@ -125,7 +125,7 @@ export default class WidgetsCore extends Core {
throw new Error("Widget id must be a string.")
}
console.debug(`🧩 Uninstalling widget with id [${widget_id}]`)
this.console.debug(`🧩 Uninstalling widget with id [${widget_id}]`)
// check if already installed
if (!this.isInstalled(widget_id)) {