5***@qq.com
5***@qq.com
  • 发布:2017-07-06 11:11
  • 更新:2020-07-23 16:37
  • 阅读:3599

急问hbuilder支持SignalR吗

分类:5+ SDK

如题,hbuilder做的客户端有个聊天功能,能支持SignalR吗,我web网页测试没有问题,放到hbuilder里面不行呢。求解!

2017-07-06 11:11 负责人:无 分享
已邀请:
2***@qq.com

2***@qq.com - 80后

同问...

  • DCloud_HB_WDL

    是uniapp 还是5+? 什么项目类型?

    2019-01-11 09:49

  • 2***@qq.com

    uniapp 连signalr

    2019-01-11 20:58

  • w***@163.com

    回复 DCloud_HB_WDL: uniapp可以用SignalR吗?有兼容问题吗

    2019-09-17 20:31

  • 2***@qq.com

    回复 DCloud_HB_WDL: app项目,h5可以但是app运行不起 exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack ->Exception: Error: module "common/request" is not defined

    2020-03-02 14:28

x***@126.com

x***@126.com - 白白的小白

同问

zhongpei

zhongpei - 1984

支持。

3***@qq.com

3***@qq.com - 80后

同问

冷魂浪子

冷魂浪子

似乎用不了,signalr需要jquery,uni用不了jquery,找了个不需要jq的版本能连接上和接收消息,但是发送消息有问题.可以尝试下.net core版的signalr,好像这个版本的可以不用jq

  • Ai洛

    有没有不用jq 的链接?

    2020-06-01 10:30

beetle2013

beetle2013

微软有个例子,它用原生JS写的,运行在Chrome中是正常工作的。
我在UNI中,改写了一下代码,在Chrome中调试,可以发消息,但是接收消息的方法没有触发。代码如下:

<template>  
    <view class="content">  
        <view>  
            <input type="text" v-model="user">  
            <input type="text" v-model="message">  
            <button @click="sendMsg">send</button>  
        </view>  
        <view>  
            <text v-for="message in messages" :key="message"></text>  
        </view>  
    </view>  
</template>  

<script>  
    import * as signalR from "@aspnet/signalr";  
    import { Toast } from "../../utils/index"  
    export default {  
        data() {  
            return {  
                connection: null,  
                messages: [],  
                user: '',  
                message: ''  
            }  
        },  
        onLoad() {  
          this.connection = new signalR.HubConnectionBuilder()  
            .withUrl("http://localhost:61625/chatHub")  
            .build();  
        },  
        onReady () {  
            this.connection.start({ transport: ['webSockets'] }).catch(err => {  
                Toast(err);  
            })  

            this.connection.on("messageReceived", (user, message) => {  
                console.log('messageReceived')  
                var msg = message.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");  
                var encodedMsg = user + " says " + msg;  
                this.messages.push(encodedMsg)  
            });  
        },  
        methods: {  
            sendMsg () {  
                this.connection.invoke("SendMessage", this.user, this.message).catch(function (err) {  
                    return console.error(err.toString());  
                });  
            }  

        }  
    }  
</script>

真机运行报错,无法运行,错误如下:

10:17:11.983 17:12.318 11603 11624 E console : [ERROR] reportJSException >>>> exception function:createInstance, exception:Exception: Error: module "common/request" is not defined  
10:17:12.013 17:12.318 11603 11624 E console : require@(global function):8:663258  
10:17:12.033 17:12.318 11603 11624 E console : (global function):8:663006  
10:17:12.063 17:12.318 11603 11624 E console : (global function):13104:30  
10:17:12.093 17:12.318 11603 11624 E console : E:\Projects\kingsland\app\node_modules\@aspnet\signalr\dist\esm\NodeHttpClient.js@(global function):13170:34  
10:17:12.113 17:12.318 11603 11624 E console : __webpack_require__@(global function):1299:35  
10:17:12.153 17:12.318 11603 11624 E console : E:\Projects\kingsland\app\node_modules\@aspnet\signalr\dist\esm\DefaultHttpClient.js@(global function):10683:42  
10:17:12.183 17:12.318 11603 11624 E console : __webpack_require__@(global function):1299:35  
10:17:12.213 17:12.318 11603 11624 E console : E:\Projects\kingsland\app\node_modules\@aspnet\signalr\dist\esm\index.js@(global function):13913:45  
10:17:12.243 17:12.318 11603 11624 E console : __webpack_require__@(global function):1299:35

求指教。

  • x***@dingtalk.com

    看了一些网友的文章后,把signalr.js中的websocket改为uni.openwebsocket等,终于可以工作了。但是又来了新的挑战: 用户不在线时的消息如何处理。

    2019-08-26 15:05

  • Ai洛

    后端是core版本的吧? 好像非core 版本的调不通

    2020-06-01 10:10

  • 芋泥波波

    回复 x***@dingtalk.com: 您好,请问可以看一下signalr.js文件吗?

    2020-09-27 13:18

叶子的翅膀

叶子的翅膀

hbuilder可以支持支持SignalR的,signalr的源码是不包含jquery,js资源引用需要使用
import * as signalR from "signalr.js路径";

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