Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHANNEL MESSAGE EVENT IS NOT GETTING ANY DATA/ CHAT SENT #122

Open
RalphLincoln opened this issue Mar 3, 2021 · 8 comments
Open

CHANNEL MESSAGE EVENT IS NOT GETTING ANY DATA/ CHAT SENT #122

RalphLincoln opened this issue Mar 3, 2021 · 8 comments

Comments

@RalphLincoln
Copy link

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)
            },
        })
    }

}
@nhan7777
Copy link

nhan7777 commented Mar 4, 2021

I have same issue on iOS SDK 1.4.3.

@plutoless
Copy link
Contributor

@RalphLincoln @nhan7777 could you pls provide logs?

@nhan7777
Copy link

nhan7777 commented Mar 4, 2021

@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.

@plutoless
Copy link
Contributor

@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?

@nhan7777
Copy link

nhan7777 commented Mar 4, 2021

@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

@RalphLincoln
Copy link
Author

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

@plutoless
Copy link
Contributor

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

@nhan7777
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants