|
@@ -6,7 +6,9 @@ import { Controller } from "../core/controller";
|
|
|
import { useCtx } from "../ctx";
|
|
|
|
|
|
export type AssetSendedCallback = (assetUri:string)=>Promise<boolean>;
|
|
|
-export type AssetType = "empty" | "image"
|
|
|
+export type AssetWebpackUriSendedCallback = (uri:string, name:string, thumbnail:string)=>Promise<boolean>;
|
|
|
+
|
|
|
+export type AssetType = "empty" | "image" | "webpackuri"
|
|
|
const RevcChangeEvent = "app.recv.change"
|
|
|
class AssetListener {
|
|
|
id = "";
|
|
@@ -35,14 +37,22 @@ export class AppMsgRecvController extends Controller {
|
|
|
|
|
|
this.appGuid = deviceCtrl.profile.appGuid;
|
|
|
|
|
|
- natsCtrl.subscribe(`send.${this.appGuid}`, async (msg:{id:string,fromKey:string, uri:string,name?:string, thumbnail?:string})=>{
|
|
|
+ natsCtrl.subscribe(`send.${this.appGuid}`, async (msg:{id:string,fromKey:string, uri:string, name?:string, thumbnail?:string})=>{
|
|
|
const listen = this.listeners.find(item=>item.id == msg.id)
|
|
|
if (!listen) return {
|
|
|
isOk: false,
|
|
|
error: "nolistener"
|
|
|
}
|
|
|
- const ok = await listen.callback(msg.uri);
|
|
|
- return JSON.stringify({ isOk: ok})
|
|
|
+ if (listen.type == "image") {
|
|
|
+ const callback = listen.callback as AssetSendedCallback
|
|
|
+ const ok = await callback(msg.uri);
|
|
|
+ return JSON.stringify({ isOk: ok})
|
|
|
+ }
|
|
|
+ if (listen.type == "webpackuri" ) {
|
|
|
+ const callback = listen.callback as AssetWebpackUriSendedCallback
|
|
|
+ const ok = await callback(msg.uri, msg.name as string, msg.thumbnail as string);
|
|
|
+ return JSON.stringify({ isOk: ok})
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
natsCtrl.subscribe(`recv.actions.${this.appGuid}`, async ()=>{
|
|
@@ -73,6 +83,18 @@ export class AppMsgRecvController extends Controller {
|
|
|
this.listeners.push(listen);
|
|
|
}
|
|
|
|
|
|
+ //添加webpackUri听者
|
|
|
+ addWebpackuriListener(actionName:string, handle: AssetWebpackUriSendedCallback) {
|
|
|
+ let listen = this.listeners.find(item=>item.actionName == actionName);
|
|
|
+ if (listen) {
|
|
|
+ listen.callback = handle as any;
|
|
|
+ return listen.id;
|
|
|
+ }
|
|
|
+ listen = new AssetListener(actionName, handle as any)
|
|
|
+ listen.type = "webpackuri";
|
|
|
+ this.listeners.push(listen);
|
|
|
+ }
|
|
|
+
|
|
|
removeListener(id:string) {
|
|
|
let listen = this.listeners.find(item=>item.id == id);
|
|
|
if (!listen) {
|