Skip to content

Commit

Permalink
将完善的开发版本转为稳定版本 (#3)
Browse files Browse the repository at this point in the history
* 更正插件加载方法,允许软件包作为插件加载

* 优化前端效果,使其适配obs

* 更新无关紧要的文件的结构

* 1.推进插件接口的完善工作:插件配置
2.推进前端插件工作

* 初步完成前端插件接口的任务,不过还是有点问题难以解决
  • Loading branch information
northgreen authored Oct 6, 2023
1 parent 8d24c8a commit 5a444ff
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 39 deletions.
38 changes: 18 additions & 20 deletions web/js/script/main_js.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require.config({
baseUrl:"/"
})
define(["js/plugin/default_plugin_mather","js/script/plugin_manager"],
function ($,pm){
define(["js/script/plugin_manager"],
function (pm){
function main()
{
console.log("lod ready")
//请求ws地址
console.log(`
console.log("lod ready")
//请求ws地址
console.log(`
__ ___ __ __ __ __ ______ ___
__ /\\ \\__ /\\_ \\ __ /\\ \\ /\\ \\ /\\ \\/\\ \\/\\__ _\\ /\\_ \\
/\\_\\ ___\\ \\ ,_\\ __ __ __ \\//\\ \\ /\\_\\ __ __ __ \\_\\ \\ ___ ___ __ __ __ __\\ \\ \\____ \\ \\ \\ \\ \\/_/\\ \\/ ___ ___ ___ ____ ___\\//\\ \\ __
Expand All @@ -19,18 +19,18 @@ define(["js/plugin/default_plugin_mather","js/script/plugin_manager"],
\\/__/
`)

//请求websocket
req = new XMLHttpRequest()
//请求websocket
let req = new XMLHttpRequest()

req.open("get","/get_websocket",true)
req.open("get","/get_websocket",true)

req.onreadystatechange=function(){
if(req.readyState === XMLHttpRequest.DONE && req.status === 200){
websocket(JSON.parse(req.responseText).local)
}

}
req.send()
req.onreadystatechange=function(){
if(req.readyState === XMLHttpRequest.DONE && req.status === 200){
//启动websocket
websocket(JSON.parse(req.responseText).local)
}
}
req.send()

}

Expand All @@ -40,19 +40,17 @@ function websocket(ura){
var socket = new WebSocket(ura)
socket.addEventListener("message",function(event){
console.log('Message from server ', event.data)

if (event.data === "{\"code\": 200, \"msg\": \"connect ok\"}"){
console.info("connect to seriver success")
connect_ok = 1
}else if (connect_ok === 1) {
console.info("cok is "+event.data)
let msg = JSON.parse(event.data)
if (msg.message_class === "default"){
let data = $.dm_halder(msg)
if (data !== void 0) {
//TODO:处理非标准消息
}
//消息处理
pm.message_handlers(msg)
}

}
})
socket.onopen=function(){
Expand Down
42 changes: 23 additions & 19 deletions web/js/script/plugin_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,48 @@ require.config({
define(
function (){
console.info("plugin system is ready")
let plugin_list = plugin_load()

//消息插件获取
let plugin_load = function (){
let get_plugin = new XMLHttpRequest()
let plugin_list = []

get_plugin.open("get","/api/plugin_list",false)

//回调
get_plugin.onreadystatechange = function () {
if (get_plugin.readyState === XMLHttpRequest.DONE && get_plugin.status === 200) {
let req = JSON.parse(get_plugin.responseText)
plugin_list = req.list
}
}
get_plugin.send()
/*
for(let a in plugin_list){
let plugin
require([plugin_list[a]],function (plug) {
plugin = plug
})
plugins[plugin_list[a]] = plugin
}
console.info("az")
* */
console.info(plugin_list)

return plugin_list
// TODO :剩余工作
}

let message_hader = function (plugin_list) {
//TODO:消息处理器
let plugin_list = plugin_load()
//消息插件列表
let plugin_message_handler = {}
//消息插件注册
for (let x in plugin_list){
require([plugin_list[x]],function (plugin){
plugin_message_handler[plugin.message_class] = plugin.dm_halder
})
}

/*消息回调*/
let message_handler = function (message) {
if (Object.keys(plugin_message_handler).length !== 0){
plugin_message_handler[message.message_class](message)
}else {
// FIXME: 似乎有个难以解决的bug,不过貌似不是很重要,在插件加载之前的消息总是不能被正确处理
console.debug("a bug?")
console.debug(plugin_message_handler)
}

}

return {
plugin_load: plugin_load,
message_halders: message_hader,
message_handlers: message_handler,
plugin_list: plugin_list
}
}
Expand Down

0 comments on commit 5a444ff

Please sign in to comment.