小编Ujj*_*har的帖子

如何使用@aspnet/signalr 库修复 reactnative 中的“错误:无法启动传输‘WebSockets’:null”?

连接到服务器时,我一直无法启动传输 'WebSockets': null。

我正在 reactnative 移动应用程序中实现一个简单的聊天。我正在使用 @aspnet/signalr(version-1.1.4) 库。我收到此错误 - 错误:无法启动传输“WebSockets”:空。 在此处查看日志 我在 chrome 中得到以下日志

componentDidMount(){

try {

      const connection = new signalR.HubConnectionBuilder() //Connect to a hub
        .withUrl(baseUrl + `/chatbus`, {
          transport: signalR.HttpTransportType.WebSockets | signalR.HttpTransportType.LongPolling,
          'content-type': 'application/json',
          accessTokenFactory: () => authToken   //for authorization
        })
        .configureLogging(signalR.LogLevel.Debug)
        .build();

      connection.on('NotifySignalR', (ChatObject) => {
        console.log(ChatObject);

      });

      connection.start()
        .then(() => {
          console.log('Chat Connection started.');
          console.log('Now connected, connection ID=' + connection.id);
          this.initalAttemptForChat = true;
          connection.invoke("start");
        })
        .catch(() => {
          this.initalAttemptForChat = false;
          console.log('Error while establishing chatbus connection!');
        });

    } catch …
Run Code Online (Sandbox Code Playgroud)

signalr react-native

8
推荐指数
1
解决办法
9541
查看次数

我需要在给定条件下从弹出菜单中隐藏/显示特定项目

我试过这个解决方案,但它没有按我预期的那样工作。
这是我的代码,这是我尝试过的。

PopupMenu popup = new PopupMenu(TableActivity.this, view);
              popup.setOnMenuItemClickListener(TableActivity.this);
              menu = popup.getMenu();
              popup.inflate(R.menu.popup_shift);
              popup.show();
              popup.setOnMenuItemClickListener(this);

    @Override
     public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.menu_merge:
                    if(tableDbList.get(positionShift).getMergeTableId()== 0) {     
                      //this is the condition to show/hide popup menuitem  
                         popup.getMenu().findItem(R.id.menu_merge).setVisible(false);
                    }else {   
                    checkPinCode.checkPinCodemethod(TableActivity.this,   "mergeCancel");
                    }
         }
     return true;
    }
Run Code Online (Sandbox Code Playgroud)

java android

2
推荐指数
1
解决办法
1338
查看次数

标签 统计

android ×1

java ×1

react-native ×1

signalr ×1