openimsdk / open-im-server

IM Chat ChatGPT
https://openim.io
Apache License 2.0
14.14k stars 2.5k forks source link

Bug: open-in-sdk happened WebSocket is not open. Message not sent. #1605

Closed anyone0034 closed 11 months ago

anyone0034 commented 11 months ago

What happened?

What did you expect to happen?

I am using the douyin mini program, the login is successful.Than,i want to sent message, it prompts that the socket has been closed.

How can we reproduce it (as minimally and precisely as possible)?

import React, { useCallback, useEffect, useRef, useState } from "react";
import {
    View,
} from "@tarojs/components";

import { Button } from '@nutui/nutui-react-taro';
import { OpenIMSDK } from 'open-im-sdk';
import { useLoad } from "@tarojs/taro";

let IMSDK = new OpenIMSDK();
let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySUQiOiIxMzIwMjYxMzU2IiwiUGxhdGZvcm1JRCI6NiwiZXhwIjoxNzExMjY5NjM5LCJuYmYiOjE3MDM0OTMzMzksImlhdCI6MTcwMzQ5MzYzOX0.CANYekmN8MUbylKBamhpITZsiPeK6TqlxzYyCSPpFhM"
let userID = '1320261356'

const Index = () => {

    useLoad(async () => {

        const config = {
            userID,
            token,
            platformID: 6,
            wsAddr: 'ws://192.168.0.241:10001',
            apiAddr: 'http://192.168.0.241:10002',
        };

        try {
            await IMSDK.login(config)
        } catch (err) {
            console.error(err);
        }
    });

    const sendMsg = async () => {
        console.log(">>>>>>>>>>> sendMsg")

        let text;
        try {
            text = await IMSDK.createTextMessage("123", '456');
        } catch (error) {
            console.error('Error CreateTextMsg:', error);
        }

        const options = {
            message: text,
            recvID: "4297749391",
            groupID: "",
        };

        IMSDK.sendMessage(options)
            .then(({ data }) => {
                // 调用成功
                console.log(">>>>>>>>>>>>>>>>> 调用成功")
                console.log(data);

            })
            .catch(({ errCode, errMsg }) => {
                // 调用失败
                console.error(">>>>>>>>>>>>>>>>> 调用失败")
                console.error(errCode);
                console.error(errMsg);
            });

    }

    return (

        <View className="page" >

            <Button
                style={{
                    marginTop: "50%",
                }}
                type="primary"
                onClick={sendMsg}
            >发送</Button>

        </View >
    );
};

export default Index;

Anything else we need to know?

No response

version

```console index.es.js:1 WebSocket is not open. Message not sent. ```

Cloud provider

OS version

```console # On Windows: C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture BuildNumber Caption OSArchitecture Version 19045 Microsoft Windows 10 企业版 64-bit 10.0.19045 ```

Install tools

kubbot commented 11 months ago

Hello! Thank you for filing an issue.

If this is a bug report, please include relevant logs to help us debug the problem.

Join slack 🤖 to connect and communicate with our developers.

kubbot commented 11 months ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Used import { OpenIMSDK } from 'open-im-sdk' Headers:

Request URL: ws://vm1:10001/?sendID=5302466161&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySUQiOiI1MzAyNDY2MTYxIiwiUGxhdGZvcm1JRCI6NiwiZXhwIjoxNzExMzc5MDE3LCJuYmYiOjE3MDM2MDI3MTcsImlhdCI6MTcwMzYwMzAxN30.YsZ3v0T9cFLntzWZO2lU3yAraOfOKzJt7NhPwuJ70kA&platformID=6&operationID=1
Request Method: GET
Status Code: 101 Switching Protocols
Connection: Upgrade
Sec-WebSocket-Accept: 20XtqShFiN9O6WfoAf/VVBwQ7mY=
Upgrade: websocket
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN
Cache-Control: no-cache
Connection: Upgrade
Host: vm1:10001
Origin: http://127.0.0.1:7045
Pragma: no-cache
Referer: https://tmaservice.developer.toutiao.com/?appid=tt65b91304fa8501e801&version=1.0.0
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Key: aULZxwXWxAs4Gg9+bYVKzQ==
Sec-WebSocket-Version: 13
Upgrade: websocket
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1 BytedanceWebview/d8a21c6 Aweme/15.9.0 Mobile ToutiaoMicroApp/2.8.0.12 @byted/miniprogram-ide
sendID: 5302466161
token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySUQiOiI1MzAyNDY2MTYxIiwiUGxhdGZvcm1JRCI6NiwiZXhwIjoxNzExMzc5MDE3LCJuYmYiOjE3MDM2MDI3MTcsImlhdCI6MTcwMzYwMzAxN30.YsZ3v0T9cFLntzWZO2lU3yAraOfOKzJt7NhPwuJ70kA
platformID: 6
operationID: 1

image

Used tt.connectSocket Headers:

Request URL: ws://vm1:10001/?sendID=5302466161&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySUQiOiI1MzAyNDY2MTYxIiwiUGxhdGZvcm1JRCI6NiwiZXhwIjoxNzExMzc5MDE3LCJuYmYiOjE3MDM2MDI3MTcsImlhdCI6MTcwMzYwMzAxN30.YsZ3v0T9cFLntzWZO2lU3yAraOfOKzJt7NhPwuJ70kA&platformID=6&operationID=cy2yyts1b1703658795984
Request Method: GET
Status Code: 101 Switching Protocols
Connection: Upgrade
Sec-WebSocket-Accept: 43woWC7JwSMyxKDaZYtTrNDPz9Y=
Upgrade: websocket
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN
Cache-Control: no-cache
Connection: Upgrade
Host: vm1:10001
Origin: http://127.0.0.1:7045
Pragma: no-cache
Referer: https://tmaservice.developer.toutiao.com/?appid=tt65b91304fa8501e801&version=1.0.0
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Key: 0L5xh11zYP0qvqvC0V6cQw==
Sec-WebSocket-Version: 13
Upgrade: websocket
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1 BytedanceWebview/d8a21c6 Aweme/15.9.0 Mobile ToutiaoMicroApp/2.8.0.12 @byted/miniprogram-ide
sendID: 5302466161
token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySUQiOiI1MzAyNDY2MTYxIiwiUGxhdGZvcm1JRCI6NiwiZXhwIjoxNzExMzc5MDE3LCJuYmYiOjE3MDM2MDI3MTcsImlhdCI6MTcwMzYwMzAxN30.YsZ3v0T9cFLntzWZO2lU3yAraOfOKzJt7NhPwuJ70kA
platformID: 6
operationID: cy2yyts1b1703658795984

image

anyone0034 commented 11 months ago

111