RTM icon indicating copy to clipboard operation
RTM copied to clipboard

CHANNEL MESSAGE EVENT IS NOT GETTING ANY DATA/ CHAT SENT

Open RalphLincoln opened this issue 3 years ago • 8 comments

My code below

import AgoraRTM from 'agora-rtm-sdk';
import EventEmitter from 'events';


export default class RTMClient extends EventEmitter {
    constructor () {
        super()
        this.channels = {}
        this._logined = false
    }

    init (appId) {
        this.client = AgoraRTM.createInstance(appId)
        this.subscribeClientEvents()
    }

    // subscribe client events
    subscribeClientEvents () {
        const clientEvents = [
        'ConnectionStateChanged',
        'MessageFromPeer'
        ]
        clientEvents.forEach((eventName) => {
            this.client.on(eventName, (...args) => {
                console.log('emit ', eventName, ...args)
                // log event message
                this.emit(eventName, ...args)
            })
        })
    }

    // subscribe channel events
    subscribeChannelEvents (channelName) {
        const channelEvents = [
        'ChannelMessage',
        'MemberJoined',
        'MemberLeft'
        ]
        channelEvents.forEach((eventName) => {
            console.log(this.channels)
            this.channels[channelName].channel.on(eventName, (...args) => {
                console.log('emit ', eventName, args)
                this.emit(eventName, { channelName, args: args })
            })
        })
    }

    async login (accountName, token) {
        this.accountName = accountName
        return this.client.login({ uid: this.accountName, token })
    }

    async logout () {
        return this.client.logout()
    }

    async joinChannel (name) {
        console.log('joinChannel', name)
        const channel = this.client.createChannel(name)
        this.channels[name] = {
            channel,
            joined: false // channel state
        }
        this.subscribeChannelEvents(name)
        console.log(channel)
        return channel.join()
    }

    async leaveChannel (name) {
        console.log('leaveChannel', name)
        if (!this.channels[name] ||
            (this.channels[name] &&
            !this.channels[name].joined)) return
        return this.channels[name].channel.leave()
    }

    async sendChannelMessage (text, channelName) {
        console.log(text, channelName)
        if (!channelName || !channelName.joined) return console.log("none")
        console.log(this.channels[channelName])
        return channelName.sendMessage({ text })
    }

    async sendPeerMessage (text, peerId) {
        console.log('sendPeerMessage', text, peerId)
        return this.client.sendMessageToPeer({ text }, peerId.toString())
    }

    async queryPeersOnlineStatus (memberId) {
        console.log('queryPeersOnlineStatus', memberId)
        return this.client.queryPeersOnlineStatus([memberId])
    }

    //send image
    async uploadImage (blob, peerId) {
        const mediaMessage = await this.client.createMediaMessageByUploading(blob, {
        messageType: 'IMAGE',
        fileName: 'agora.jpg',
        description: 'send image',
        thumbnail: blob, 
        // width: 100,
        // height: 200,
        // thumbnailWidth: 50,
        // thumbnailHeight: 200, 
        }) 
        return this.client.sendMessageToPeer(mediaMessage, peerId)
    }

    async sendChannelMediaMessage (blob, channelName) {
        console.log('sendChannelMessage', blob, channelName)
        if (!this.channels[channelName] || !this.channels[channelName].joined) return
        const mediaMessage = await this.client.createMediaMessageByUploading(blob, {
            messageType: 'IMAGE',
            fileName: 'agora.jpg',
            description: 'send image',
            thumbnail: blob, 
            // width: 100,
            // height: 200,
            // thumbnailWidth: 50,
            // thumbnailHeight: 200, 
        }) 
        return this.channels[channelName].channel.sendMessage(mediaMessage)
    }

    async cancelImage (message) {
        const controller = new AbortController()
        setTimeout(() => controller.abort(), 1000)
        await this.client.downloadMedia(message.mediaId, {
            cancelSignal: controller.signal,
            onOperationProgress: ({currentSize, totalSize}) => {
                console.log(currentSize, totalSize)
            },
        })
    }

}

RalphLincoln avatar Mar 03 '21 10:03 RalphLincoln

I have same issue on iOS SDK 1.4.3.

nhan7777 avatar Mar 04 '21 11:03 nhan7777

@RalphLincoln @nhan7777 could you pls provide logs?

plutoless avatar Mar 04 '21 11:03 plutoless

@RalphLincoln @nhan7777 could you pls provide logs?

No log here. Client logined successfully. I tried debug breakpoint at function (void)channel:(AgoraRtmChannel *)channel messageReceived:(AgoraRtmMessage *)message fromMember:(AgoraRtmMember *)member but nothing happened.

nhan7777 avatar Mar 04 '21 11:03 nhan7777

@nhan7777 if you can provide your log it will be easier for me to understand your situation. if not maybe you can provide your source code or reproducible project?

plutoless avatar Mar 04 '21 11:03 plutoless

@plutoless you can try this example https://github.com/AgoraIO/Agora-Flutter-RTM-SDK. I tried debug native sdk. Maybe it is an issue of server side

nhan7777 avatar Mar 04 '21 12:03 nhan7777

@plutoless try my code above and see if it works!!

RalphLincoln avatar Mar 06 '21 19:03 RalphLincoln

@RalphLincoln hi your code is just a class definition. i have no idea how you instantiate the class and use.

plutoless avatar Mar 08 '21 10:03 plutoless

@plutoless Did you try the example? Does it work?

nhan7777 avatar Mar 11 '21 07:03 nhan7777