所以我面临的主要问题是,当我尝试从kaiEvents.onKaiConnected()范围之外的photoshop.ts调用kai.setCapabilities()时,它可以正常工作,但是只要我尝试调用函数kaiEvents.onKaiConnected()范围内的函数kai.setCapabilities()执行该函数,但是Web套接字(index.ts)不发送数据。 我正在使用事件发射器和侦听器。 (emitter.ts)
我的index.ts文件中包含以下代码:
var get_Token = async () => {
const token = await getToken();
return token;
};
const getToken = async () => {
$.get("example.endpoing.org").success(function(res) {
return res;
});
};
var token = get_Token();
$(document).ready(function(token) {
$("#access_token").val(token);
});
和下面的generator.ts文件中的内容:
export function setCapabilities(kaiId:number,capabilities:object){
var request:object = {
type: 'setCapabilities',
kaiId: kaiId
}
let req = {...request,...capabilities}
ws.on('open',function(){
ws.send(JSON.stringify(req));
});
}
if(response['success']){
switch(response['type']){
case 'setCapabilities':
kaiEvents.emit('setCapabilities',response)
capabilitiesSet = true
break;
}
}
以及photoshop.ts中的以下内容
onSetCapabilities(handler:any){
this.addListener('setCapabilities',handler);
}
onKaiConnected(handler:any) {
this.addListener('kaiConnected',handler) ;
}