uie糖心甜酒 2019-10-30 14:55 采纳率: 50%
浏览 2682

(Vue/wfs.js)为什么不能调用wfs.js里的websocket初始化和关闭函数,只能调用发送函数?

由于项目要进行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,可以直接在外部调用我定义的所有方法,包括初始化和关闭。不明白为什么这里不行。

  • 写回答

1条回答

  • syf_wfl 2021-10-23 18:50
    关注

    楼主这个问题解决了吗,现在我也遇到了这个问题,不知道怎么关闭,能分享下吗🙏

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题