由于项目要进行H.264裸流播放,在github上找到了可用的
wfs.js,最近又遇到了一个问题,无法调用wfs.js内部Websocket初始化和关闭的函数。
之前经过提问已经解决了
调用函数内部函数的问题,答案中的链接地址是https://blog.csdn.net/weixin_43694639/article/details/88723280,
但是我用同样的写法,却不能调用websocket的关闭函数,只能调用发送数据的函数。
这是整个函数折叠起来的样子:
(function(f)){...
})(function() {...
});
这是我要调用的函数整体:
var WebsocketLoader = function(_EventHandler){
_inherits(WebsocketLoader, _EventHandler);
function WebsocketLoader(wfs){...
}
_createClass(WebsocketLoader, [{... //要调用的函数在省略号里
}]);
return WebsocketLoader;
}(_eventHandler2.default);
exports.default = WebsocketLoader;
不能调用的函数,初始化websocket:
key: 'initSocketClient',
value: function initSocketClient() {
this.client.binaryType = 'arraybuffer';
this.client.onmessage = this.receiveSocketMessage.bind(this);
// clientSocket.binaryType = 'arraybuffer';
// clientSocket.onmessage = socketReceive;
this.wfs.trigger(_events2.default.WEBSOCKET_MESSAGE_SENDING, { commandType: "open", channelName: this.channelName, commandValue: "NA" }); //不知道这个trigger是什么
console.log('Websocket Open!');
flagSP = true;
//initSocket = initSocketClient
不能调用的函数,主动关闭websocket:
//这个函数是我后来自己加的
key: 'onWebsocketClose',
value: function onWebsocketClose(i) {
clientSocket.send(i)
console.log('切换页面,中断连接。' + i)
clientSocket.close();
socketClose = onWebsocketClose;
每次调用都会报这个错:
[Vue warn]: Error in v-on handler: "TypeError: Object(...) is not a function"
found in
---> <WindowFrame> at src/components/WindowFrame.vue
<ElHeader> at packages/header/src/main.vue
<ElContainer> at packages/container/src/main.vue
<Ccqg> at src/components/main.vue
<App> at src/App.vue
<Root> vue.esm.js:628
TypeError: "Object(...) is not a function"
showMain WindowFrame.vue:309
click WindowFrame.vue:268
VueJS 3
但是这个函数可以在外部调用:
key: 'onWebsocketMessageSending',
value: function onWebsocketMessageSending(i) {
clientSocket.send(i)
console.log('发送视频请求:' + i)
//this.client.send(i)
//this.client.send(JSON.stringify({ type: 2, carNum: 8888 }))
sendMsg = onWebsocketMessageSending
我之前写过单独的websocket,可以直接在外部调用我定义的所有方法,包括初始化和关闭。不明白为什么这里不行。