mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
use new core
class from runtime
This commit is contained in:
parent
29e3ad5878
commit
11b52595c1
@ -1,4 +1,4 @@
|
|||||||
import { Core } from "vessel"
|
import { Core } from "@ragestudio/vessel"
|
||||||
|
|
||||||
import createClient from "comty.js"
|
import createClient from "comty.js"
|
||||||
|
|
||||||
@ -8,87 +8,99 @@ import useRequest from "comty.js/hooks/useRequest"
|
|||||||
import { reconnectWebsockets, disconnectWebsockets } from "comty.js"
|
import { reconnectWebsockets, disconnectWebsockets } from "comty.js"
|
||||||
|
|
||||||
export default class APICore extends Core {
|
export default class APICore extends Core {
|
||||||
static namespace = "api"
|
static namespace = "api"
|
||||||
|
|
||||||
static bgColor = "coral"
|
static bgColor = "coral"
|
||||||
static textColor = "black"
|
static textColor = "black"
|
||||||
|
|
||||||
client = null
|
client = null
|
||||||
|
|
||||||
public = {
|
public = {
|
||||||
client: function () {
|
client: function () {
|
||||||
return this.client
|
return this.client
|
||||||
}.bind(this),
|
}.bind(this),
|
||||||
customRequest: request,
|
customRequest: request,
|
||||||
listenEvent: this.listenEvent.bind(this),
|
listenEvent: this.listenEvent.bind(this),
|
||||||
unlistenEvent: this.unlistenEvent.bind(this),
|
unlistenEvent: this.unlistenEvent.bind(this),
|
||||||
measurePing: measurePing,
|
measurePing: measurePing,
|
||||||
useRequest: useRequest,
|
useRequest: useRequest,
|
||||||
reconnectWebsockets: reconnectWebsockets,
|
reconnectWebsockets: reconnectWebsockets,
|
||||||
disconnectWebsockets: disconnectWebsockets,
|
disconnectWebsockets: disconnectWebsockets,
|
||||||
}
|
}
|
||||||
|
|
||||||
listenEvent(key, handler, instance = "default") {
|
registerSocketListeners = (map) => {
|
||||||
if (!this.client.sockets[instance]) {
|
Object.entries(map).forEach(([namespace, listeners]) => {
|
||||||
this.console.error(`[API] Websocket instance ${instance} not found`)
|
Object.entries(listeners).forEach(([event, handler]) => {
|
||||||
|
this.listenEvent(event, handler, namespace)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
listenEvent(key, handler, instance = "default") {
|
||||||
}
|
if (!this.client.sockets[instance]) {
|
||||||
|
this.console.error(`[API] Websocket instance ${instance} not found`)
|
||||||
|
|
||||||
return this.client.sockets[instance].on(key, handler)
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
unlistenEvent(key, handler, instance = "default") {
|
return this.client.sockets[instance].on(key, handler)
|
||||||
if (!this.client.sockets[instance]) {
|
}
|
||||||
this.console.error(`[API] Websocket instance ${instance} not found`)
|
|
||||||
|
|
||||||
return false
|
unlistenEvent(key, handler, instance = "default") {
|
||||||
}
|
if (!this.client.sockets[instance]) {
|
||||||
|
this.console.error(`[API] Websocket instance ${instance} not found`)
|
||||||
|
|
||||||
return this.client.sockets[instance].off(key, handler)
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
async onInitialize() {
|
return this.client.sockets[instance].off(key, handler)
|
||||||
this.client = await createClient({
|
}
|
||||||
enableWs: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
this.client.eventBus.on("ws:disconnected", () => {
|
async onInitialize() {
|
||||||
app.cores.notifications.new({
|
this.client = await createClient({
|
||||||
title: "Failed to connect to server",
|
enableWs: true,
|
||||||
description: "The connection to the server was lost. Some features may not work properly.",
|
//origin: "https://indev.comty.app/api"
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
this.client.eventBus.on("auth:login_success", () => {
|
this.client.eventBus.on("ws:disconnected", () => {
|
||||||
app.eventBus.emit("auth:login_success")
|
app.cores.notifications.new({
|
||||||
})
|
title: "Failed to connect to server",
|
||||||
|
description:
|
||||||
|
"The connection to the server was lost. Some features may not work properly.",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
this.client.eventBus.on("auth:logout_success", () => {
|
this.client.eventBus.on("auth:login_success", () => {
|
||||||
app.eventBus.emit("auth:logout_success")
|
app.eventBus.emit("auth:login_success")
|
||||||
})
|
})
|
||||||
|
|
||||||
this.client.eventBus.on("session.invalid", (error) => {
|
this.client.eventBus.on("auth:logout_success", () => {
|
||||||
app.eventBus.emit("session.invalid", error)
|
app.eventBus.emit("auth:logout_success")
|
||||||
})
|
})
|
||||||
|
|
||||||
this.client.eventBus.on("auth:disabled_account", () => {
|
this.client.eventBus.on("session.invalid", (error) => {
|
||||||
app.eventBus.emit("auth:disabled_account")
|
app.eventBus.emit("session.invalid", error)
|
||||||
})
|
})
|
||||||
|
|
||||||
// make a basic request to check if the API is available
|
this.client.eventBus.on("auth:disabled_account", () => {
|
||||||
await this.client.baseRequest({
|
app.eventBus.emit("auth:disabled_account")
|
||||||
method: "head",
|
})
|
||||||
url: "/",
|
|
||||||
}).catch((error) => {
|
|
||||||
this.console.error("[API] Ping error", error)
|
|
||||||
|
|
||||||
throw new Error(`
|
// make a basic request to check if the API is available
|
||||||
|
await this.client
|
||||||
|
.baseRequest({
|
||||||
|
method: "head",
|
||||||
|
url: "/",
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
this.console.error("[API] Ping error", error)
|
||||||
|
|
||||||
|
throw new Error(`
|
||||||
Could not connect to the API.
|
Could not connect to the API.
|
||||||
Please check your connection and try again.
|
Please check your connection and try again.
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
|
|
||||||
return this.client
|
return this.client
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
|
|
||||||
import { Core, EventBus } from "vessel"
|
import { Core, EventBus } from "@ragestudio/vessel"
|
||||||
|
|
||||||
import ContextMenu from "./components/contextMenu"
|
import ContextMenu from "./components/contextMenu"
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Core } from "vessel"
|
import { Core } from "@ragestudio/vessel"
|
||||||
import { FFmpeg } from "@ffmpeg/ffmpeg"
|
import { FFmpeg } from "@ffmpeg/ffmpeg"
|
||||||
import { fetchFile, toBlobURL } from "@ffmpeg/util"
|
import { fetchFile, toBlobURL } from "@ffmpeg/util"
|
||||||
import isURL from "@utils/isURL"
|
import isURL from "@utils/isURL"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Core } from "vessel"
|
import { Core } from "@ragestudio/vessel"
|
||||||
import { Haptics } from "@capacitor/haptics"
|
import { Haptics } from "@capacitor/haptics"
|
||||||
|
|
||||||
const vibrationPatterns = {
|
const vibrationPatterns = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Core } from "vessel"
|
import { Core } from "@ragestudio/vessel"
|
||||||
import i18n from "i18next"
|
import i18n from "i18next"
|
||||||
import { initReactI18next } from "react-i18next"
|
import { initReactI18next } from "react-i18next"
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Core } from "vessel"
|
import { Core } from "@ragestudio/vessel"
|
||||||
import TapShareDialog from "@components/TapShare/Dialog"
|
import TapShareDialog from "@components/TapShare/Dialog"
|
||||||
|
|
||||||
const RecordTypes = {
|
const RecordTypes = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Core } from "vessel"
|
import { Core } from "@ragestudio/vessel"
|
||||||
|
|
||||||
import NotificationUI from "./ui"
|
import NotificationUI from "./ui"
|
||||||
import NotificationFeedback from "./feedback"
|
import NotificationFeedback from "./feedback"
|
||||||
@ -10,13 +10,14 @@ export default class NotificationCore extends Core {
|
|||||||
"settings",
|
"settings",
|
||||||
]
|
]
|
||||||
|
|
||||||
#newNotifications = []
|
|
||||||
|
|
||||||
listenSockets = {
|
listenSockets = {
|
||||||
"notifications": {
|
"notifications": {
|
||||||
"notification.new": (data) => {
|
"notification.new": (data) => {
|
||||||
this.new(data)
|
this.new(data)
|
||||||
}
|
},
|
||||||
|
"notification.broadcast": (data) => {
|
||||||
|
this.new(data)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,6 +26,10 @@ export default class NotificationCore extends Core {
|
|||||||
close: this.close,
|
close: this.close,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async onInitialize() {
|
||||||
|
this.ctx.CORES.api.registerSocketListeners(this.listenSockets)
|
||||||
|
}
|
||||||
|
|
||||||
async new(notification) {
|
async new(notification) {
|
||||||
NotificationUI.notify(notification)
|
NotificationUI.notify(notification)
|
||||||
NotificationFeedback.feedback(notification)
|
NotificationFeedback.feedback(notification)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Core } from "vessel"
|
import { Core } from "@ragestudio/vessel"
|
||||||
import store from "store"
|
import store from "store"
|
||||||
import { Observable } from "rxjs"
|
import { Observable } from "rxjs"
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Core } from "vessel"
|
import { Core } from "@ragestudio/vessel"
|
||||||
import { Howl } from "howler"
|
import { Howl } from "howler"
|
||||||
import axios from "axios"
|
import axios from "axios"
|
||||||
import store from "store"
|
import store from "store"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Core } from "vessel"
|
import { Core } from "@ragestudio/vessel"
|
||||||
|
|
||||||
export default class ShortcutsCore extends Core {
|
export default class ShortcutsCore extends Core {
|
||||||
static namespace = "shortcuts"
|
static namespace = "shortcuts"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import { Core } from "vessel"
|
import { Core } from "@ragestudio/vessel"
|
||||||
|
|
||||||
import { ConfigProvider, theme } from "antd"
|
import { ConfigProvider, theme } from "antd"
|
||||||
import store from "store"
|
import store from "store"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Core } from "vessel"
|
import { Core } from "@ragestudio/vessel"
|
||||||
import SyncModel from "comty.js/models/sync"
|
import SyncModel from "comty.js/models/sync"
|
||||||
|
|
||||||
export default class SyncCore extends Core {
|
export default class SyncCore extends Core {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Core } from "vessel"
|
import { Core } from "@ragestudio/vessel"
|
||||||
import { Observable } from "object-observer"
|
import { Observable } from "object-observer"
|
||||||
|
|
||||||
export default class TasksQueue extends Core {
|
export default class TasksQueue extends Core {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Core } from "vessel"
|
import { Core } from "@ragestudio/vessel"
|
||||||
import store from "store"
|
import store from "store"
|
||||||
|
|
||||||
export default class WidgetsCore extends Core {
|
export default class WidgetsCore extends Core {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import { Core } from "vessel"
|
import { Core } from "@ragestudio/vessel"
|
||||||
|
|
||||||
import { createRoot } from "react-dom/client"
|
import { createRoot } from "react-dom/client"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user