RTM:ERROR 错误代码 102: sendMessage 失败,参数为:"messageType":"TEXT"

Posted

技术标签:

【中文标题】RTM:ERROR 错误代码 102: sendMessage 失败,参数为:"messageType":"TEXT"【英文标题】:RTM:ERROR Error Code 102: sendMessage failed with args: "messageType":"TEXT"RTM:ERROR 错误代码 102: sendMessage 失败,参数为:"messageType":"TEXT" 【发布时间】:2021-04-19 04:38:54 【问题描述】:

我正在使用 Agora RTM WebSDK 的频道消息来开发聊天服务。我想调用 sendMessage 方法并在按下发送按钮时发送输入消息(带有 id 的输入元素是“消息”)。但是,发生了 RTM ERROR,调用 sendMessage 方法时 sendMessage 方法不起作用。我确认生成了令牌并且登录成功。脚本和错误如下。

<template>
    <div>
        <table class="comment-sender-box">
            <tr>
                <td colspan="3">
                    <textarea id="chatBox" rows="4" cols="40"> messages </textarea>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="message-wrapper">
                    <input id="message" v-model="message">
                </td>
                <td class="btnSendMessage-wrapper">
                    <button id="btnSendMessage">
                        <font-awesome-icon icon="paper-plane" />
                    </button>
                </td>            
            </tr>
        </table>
        
    </div>
</template>

<script>
    import Vue from 'vue';
    import RtcTokenBuilder, RtmTokenBuilder, RtcRole, RtmRole from 'agora-access-token';
    import AgoraRTM from 'agora-rtm-sdk';
    import  library  from '@fortawesome/fontawesome-svg-core';
    import  fas  from '@fortawesome/free-solid-svg-icons';
    import  fab  from '@fortawesome/free-brands-svg-icons';
    import  far  from '@fortawesome/free-regular-svg-icons';
    import  FontAwesomeIcon  from '@fortawesome/vue-fontawesome';
    library.add(fas, far, fab);
    Vue.component('font-awesome-icon', FontAwesomeIcon);

    export default Vue.extend(
        data: 
            name: '',
            messages: '',
            message: ''
        ,
        async created() 
            this.name = this.$route.query.user;
            var user_id = this.name;
            const appID = "**********";
            const channelName = "**********";

            const chat_token = await function()
                const appCertificate = "**********";
                const role = RtmRole.Rtm_User;
                const expirationTimeInSeconds = 36000;
                const currentTimestamp = Math.floor(Date.now() / 1000);
                const privilegeExpiredTs = currentTimestamp + expirationTimeInSeconds;
                const token = RtmTokenBuilder.buildToken(appID, appCertificate, user_id, role, privilegeExpiredTs);
                console.log("RTM Token : " + token);
                return token
            ;

            const chat_client = AgoraRTM.createInstance(appID);
            chat_client.on('ConnectionStateChanged', (newState, reason) => 
                console.log('on connection state changed to ' + newState + ' reason: ' + reason);
            );
            chat_client.login( token: chat_token(), uid: user_id ).then(() => 
                console.log('AgoraRTM client login success');
            ).catch(err => 
                console.log('AgoraRTM client login failure', err);
            );
            const chat_channel = chat_client.createChannel(channelName);
            chat_channel.join().then(() => ).catch(error => );
            chat_channel.on('ChannelMessage', ( text , senderId) => 
                this.messages = this.messages + "\n" + text;
            );

            document.getElementById("btnSendMessage").addEventListener("click", ()=>
                chat_channel.sendMessage(text: 'test message').then(() => 
                    this.messages = this.messages + "\n" + this.message;
                ).catch(error => );
            )
        
    )

</script>
RTM:ERROR Error Code 102: sendMessage failed with args: "messageType":"TEXT".

【问题讨论】:

【参考方案1】:

根据官方文档:Check here

错误代码102

建议

当您开始发送频道消息时,登录操作未完成。

【讨论】:

以上是关于RTM:ERROR 错误代码 102: sendMessage 失败,参数为:"messageType":"TEXT"的主要内容,如果未能解决你的问题,请参考以下文章

102 (net::ERR_CONNECTION_REFUSED)

Facebook SDK - iOS - 分享 URL 失败(错误 102)

连接到 JIRA 时出现间歇性 102 错误 (ERR_CONNECTION_REFUSED)

Web 视图无法加载特定 URL(Web 工具包错误域 102)

使用CLIENT KILL USERRedis 5.9.102上的语法错误

MSSQL,PDO,插入 XML 字符串时出错:一般错误:102 '<?xml version="1.0" 附近的语法不正确