凌岳
凌岳
  • 发布:2020-03-19 21:06
  • 更新:2020-03-30 15:01
  • 阅读:2826

【报Bug】uniapp引入@microsoft/signalr 自定义制作基座 编译APP端 报错

分类:uni-app

详细问题描述

reportJSException >>>> exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack ->Exception: TypeError: undefined is not an object (evaluating 'modules[moduleId].call')
18:56:32.468 webpack_require
18:56:32.510
webpack_require

18:56:32.552 webpack_require
18:56:32.594
webpack_require

18:56:32.636 webpack_require
18:56:32.657 webpackUniversalModuleDefinition
18:56:32.699 eval code
18:56:32.719 eval@[native code]
18:56:32.740 weex createInstanceContext:5908:5
18:56:32.761
webpack_require
@weex createInstanceContext:5219:35
18:56:32.803 eval code
18:56:32.824 eval@[native code]
18:56:32.845 weex createInstanceContext:5792:5
18:56:32.866 webpack_require@weex createInstanceContext:5219:35
18:56:32.909 eval code
18:56:32.929 eval@[native code]
18:56:32.949 weex createInstanceContext:5063:5
18:56:32.970
webpack_require
@weex createInstanceContext:5219:35
18:56:32.990 checkDeferredModules@weex createInstanceContext:5176:45
18:56:33.011 weex createInstanceContext:5054:61
18:56:33.032 require@weex createInstanceContext:4:665986
18:56:33.053 weex createInstanceContext:4:665601
18:56:33.074 weex createInstanceContext:6939:8
18:56:33.094 require@weex createInstanceContext:4:665986
18:56:33.115 global code@weex createInstanceContext:6941:8
18:56:33.157 getTemplateInfo== template md5 34d853a0663683dc59b704d2a87f0717 length 10700725 base64 md5 NNhToGY2g9xZtwTSqH8HFw== response header {"templateSourceBase64MD5":["NNhToGY2g9xZtwTSqH8HFw=="],"templateSourceMD5":["34d853a0663683dc59b704d2a87f0717"]}
19:03:08.247 已停止运行...

[内容]

重现步骤

[步骤]

[结果]

[期望]

[如果语言难以表述清晰,拍一个视频或截图,有图有真相]

IDE运行环境说明

[HBuilder 或 HBuilderX。如果你用其他工具开发uni-app,也需要在此说明]

[IDE版本号]

[windows版本号]

[mac版本号]

uni-app运行环境说明

[运行端是h5或app或某个小程序?]

[运行端版本号]

[项目是cli创建的还是HBuilderX创建的?如果是cli创建的,请更新到最新版cli再试]

[编译模式说明:自定义组件模式?纯nvue模式?v3模式?]

App运行环境说明

[Android版本号]

[iOS版本号]

[手机型号]

[模拟器型号]

附件

[IDE问题请提供HBuilderX运行日志。菜单帮助-查看运行日志,点右键打开文件所在目录,将log文件压缩成zip包上传]

[App问题请提供可重现问题的代码片段,你补充的细一点,问题就解决的快一点]

[App安装包或H5地址]

[可重现代码片段]

联系方式

[QQ]

2020-03-19 21:06 负责人:无 分享
已邀请:
凌岳

凌岳 (作者) - 但是ds

解决方案 小程序 -- APP 通用

const protocal = {
protocol: "json",
version: 1
};

const MessageType = {
/ Indicates the message is an Invocation message and implements the {@link InvocationMessage} interface. */
Invocation: 1,
/* Indicates the message is a StreamItem message and implements the {@link StreamItemMessage} interface. /
StreamItem: 2,
/
Indicates the message is a Completion message and implements the {@link CompletionMessage} interface. */
Completion: 3,
/ Indicates the message is a Stream Invocation message and implements the {@link StreamInvocationMessage} interface. */
StreamInvocation: 4,
/* Indicates the message is a Cancel Invocation message and implements the {@link CancelInvocationMessage} interface. /
CancelInvocation: 5,
/
Indicates the message is a Ping message and implements the {@link PingMessage} interface. */
Ping: 6,
/* Indicates the message is a Close message and implements the {@link CloseMessage} interface. /
Close: 7,
}

export class HubConnection {

constructor() {
this.openStatus = false;
this.methods = {};
this.negotiateResponse = {};
this.connection = {};
this.url = "";
this.invocationId = 0;
this.callbacks = {};
}

start(url, queryString) {
var negotiateUrl = url + "/negotiate";
if (queryString) {
for (var query in queryString) {
negotiateUrl += (negotiateUrl.indexOf("?") < 0 ? "?" : "&") + (${query}= + encodeURIComponent(queryString[query]));
}
}
uni.request({
url: negotiateUrl,
method: "post",
async: false,
success: res => {
this.negotiateResponse = res.data;
this.startSocket(negotiateUrl.replace("/negotiate", ""));
},
fail: res => {
console.error(requrst ${url} error : ${res});
return;
}
});

}

startSocket(url) {
url += (url.indexOf("?") < 0 ? "?" : "&") + ("id=" + this.negotiateResponse.connectionId);
url = url.replace(/^http/, "ws");
this.url = url;
if (this.connection != null && this.openStatus) {
return;
}

this.connection = uni.connectSocket({  
  url: url,  
  method: "get",  
  success:()=>{}  
})  

this.connection.onOpen(res => {  
  console.log(`websocket connectioned to ${this.url}`);  
  this.sendData(protocal);  
  this.openStatus = true;  
  this.onOpen(res);  
});  

this.connection.onClose(res => {  
  console.log(`websocket disconnection`);  
  this.connection = null;  
  this.openStatus = false;  
  this.onClose(res);  
});  

this.connection.onError(res => {  
  console.error(`websocket error msg: ${msg}`);  
  this.close({  
    reason: msg  
  });  
  this.onError(res)  
});  

this.connection.onMessage(res => this.receive(res));  

}

on(method, fun) {

let methodName = method.toLowerCase();  
if (this.methods[methodName]) {  
  this.methods[methodName].push(fun);  
} else {  
  this.methods[methodName] = [fun];  

}  

}

onOpen(data) { }

onClose(msg) {

}

onError(msg) {

}

close(data) {
if (data) {
this.connection.close(data);
} else {
this.connection.close();
}

this.openStatus = false;  

}

sendData(data, success, fail, complete) {
this.connection.send({
data: JSON.stringify(data) + "", //
success: success,
fail: fail,
complete: complete
});
}

receive(data) {
if (data.data.length > 3) {
data.data = data.data.replace('{}', "")
}

var messageDataList = data.data.split("");  

//循环处理服务端信息  
for (let serverMsg of messageDataList) {  
  if (serverMsg) {  
    var messageData = serverMsg.replace(new RegExp("", "gm"), "")  
    var message = JSON.parse(messageData);  

    switch (message.type) {  
      case MessageType.Invocation:  
        this.invokeClientMethod(message);  
        break;  
      case MessageType.StreamItem:  
        break;  
      case MessageType.Completion:  
        var callback = this.callbacks[message.invocationId];  
        if (callback != null) {  
          delete this.callbacks[message.invocationId];  
          callback(message);  
        }  
        break;  
      case MessageType.Ping:  
        // Don't care about pings  
        break;  
      case MessageType.Close:  
        console.log("Close message received from server.");  
        this.close({  
          reason: "Server returned an error on close"  
        });  
        break;  
      default:  
        console.warn("Invalid message type: " + message.type);  
    }  
  }  
}  

}

send(functionName) {

var args = [];  
for (var _i = 1; _i < arguments.length; _i++) {  
  args[_i - 1] = arguments[_i];  
}  

this.sendData({  
  target: functionName,  
  arguments: args,  
  type: MessageType.Invocation,  
  invocationId: this.invocationId.toString()  
});  
this.invocationId++;  

}

invoke(functionName) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}

var _this = this;  
var id = this.invocationId;  
var p = new Promise(function (resolve, reject) {  

  _this.callbacks[id] = function (message) {  
    if (message.error) {  
      reject(new Error(message.error));  
    } else {  
      resolve(message.result);  
    }  
  }  

  _this.sendData({  
    target: functionName,  
    arguments: args,  
    type: MessageType.Invocation,  
    invocationId: _this.invocationId.toString()  
  }, null, function (e) {  
    reject(e);  
  });  

});  
this.invocationId++;  
return p;  

}

invokeClientMethod(message) {
var methods = this.methods[message.target.toLowerCase()];
if (methods) {
methods.forEach(m => m.apply(this, message.arguments));
if (message.invocationId) {
// This is not supported in v1. So we return an error to avoid blocking the server waiting for the response.
var errormsg = "Server requested a response, which is not supported in this version of the client.";
console.error(errormsg);
this.close({
reason: errormsg
});
}
} else {
console.warn(No client method with the name '${message.target}' found.);
}
}
}

s***@outlook.com

s***@outlook.com - 简单传递美好,

你这nvue也用signalr,windows啥的元素在APP端没用的

  • 凌岳 (作者)

    知道这个怎么解决吗 app 端要用signalr 推送

    2020-03-19 22:19

凌岳

凌岳 (作者) - 但是ds

本人已解决 重新signalr js

  • Ai洛

    大佬 怎么解决的?@aspnet/signalr 这个是只支持core吗?

    2020-06-01 10:27

凌岳

凌岳 (作者) - 但是ds

解释上面 的方案 针对引入js 是@aspnet/signalr 别下载错了

  • 2***@qq.com

    您好,请问你能支持app了吗?

    2021-05-25 20:12

该问题目前已经被锁定, 无法添加新回复