Expand my Community achievements bar.

Chat user is not getting message from the other users

Avatar

Level 2

In my application when user [A] initiate the chat with user[B]  , I am facing following issues

-          User[B] is not getting initiation notification so that I am unable to open chat pod for user [A] on user[B] application

-          Due to above problem , User[B] not getting any message sent by the User[A]

-          User[A] can send only one message and it is displayed on simple chat pod

when User[A]tries to send more then one message it is not displayed on simple chat pod but on the console I can see the messages

following is sample code

public function connectChat() :void

{

_collectionNode =

new CollectionNode();

_collectionNode.sharedID = NOTIFICATION_COLLECTION_NODE;

_collectionNode.connectSession =

this.connectSession;

_collectionNode.addEventListener(CollectionNodeEvent.SYNCHRONIZATION_CHANGE, onSynchronizationChange,

false, 0, true);

_collectionNode.addEventListener(CollectionNodeEvent.ITEM_RECEIVE, onItemReceive,

false, 0, true);

_collectionNode.subscribe();

}

/**

* @private

* Handles the creation of a collection node if it does not already exist

*/

protected function onSynchronizationChange(event:CollectionNodeEvent):void {

if (_collectionNode.isSynchronized) {

if (!_collectionNode.isNodeDefined(START_CHAT_LIST) && _collectionNode.canUserConfigure(connectSession.userManager.myUserID)) {

_collectionNode.createNode(START_CHAT_LIST,

new NodeConfiguration(UserRoles.VIEWER, UserRoles.VIEWER, true, false, true,false, NodeConfiguration.STORAGE_SCHEME_QUEUE));

}

}

}

public function connectChat() :void

{

trace('connectChat');

_collectionNode =

new CollectionNode();

_collectionNode.sharedID = NOTIFICATION_COLLECTION_NODE;

_collectionNode.connectSession =

this.connectSession;

_collectionNode.addEventListener(CollectionNodeEvent.SYNCHRONIZATION_CHANGE, onSynchronizationChange,

false, 0, true);

_collectionNode.addEventListener(CollectionNodeEvent.ITEM_RECEIVE, onItemReceive,

false, 0, true);

_collectionNode.subscribe();

}

/**

* @private

* Handles the creation of a collection node if it does not already exist

*/

protected function onSynchronizationChange(event:CollectionNodeEvent):void {

if (_collectionNode.isSynchronized) {

//Creates the nodes if they don't exist

if (!_collectionNode.isNodeDefined(START_CHAT_LIST) && _collectionNode.canUserConfigure(connectSession.userManager.myUserID)) {

_collectionNode.createNode(START_CHAT_LIST,

new NodeConfiguration(UserRoles.VIEWER, UserRoles.VIEWER, true, false, true,false, NodeConfiguration.STORAGE_SCHEME_QUEUE));

}

}

}

/**

* Checks if a chat is going to be started with this specific user

*/

protected function onItemReceive(event:CollectionNodeEvent):void {

var item:MessageItem = event.item;

var openChatEvent:OpenChatEvent = OpenChatEvent.ToOpenChatEvent( item.body, OpenChatEvent.OPEN_CHAT );

switch (item.nodeName) {

case START_CHAT_LIST:

trace("Starting Chat Notified");

if( openChatEvent.userId && openChatEvent.userId == this.connectSession.userManager.myUserID )

{

this.dispatchEvent( openChatEvent );

if( this._collectionNode.isSynchronized )

this._collectionNode.retractItem( START_CHAT_LIST, openChatEvent.roomId );

}

break;

}

}

/**

* Publishes a request for someone to join a chat

*/

public function publishChatRequest(notificationEvent : NotificationEvent) :void {

if( this.connectSession.userManager.getUserDescriptor( notificationEvent.userID ) )

{

var openChatEvent:OpenChatEvent = new OpenChatEvent( OpenChatEvent.PUBLISH_CHAT,null,notificationEvent.sharedID, notificationEvent.userNotificationList, null, notificationEvent.userID );

if( this.presenceUsers )

openChatEvent.descriptors =

this.presenceUsers;

_collectionNode.publishItem(

new MessageItem( START_CHAT_LIST, openChatEvent, openChatEvent.roomId ) );

}

else

{

Alert.show(

"User "+ notificationEvent.userID + " is not logged in.", "Publish Error" );

}

}

}

2 Replies

Avatar

Former Community Member

Hi Ritesh,

I'm trying to narrow down what you're doing -

A) are these methods copied twice in the code here on purpose?

B) are both users subscribing to _collectionNode right away? Do each of them

get to onSynchronizationChange?

C) If you put a breakpoint in onSynchronizationChange, do you see the node

get created? Do you see it in the dev console?

D) Is user B receiving an onItemReceive at all? Is user A?

E) I don't think you should be setting the 3rd parameter in your messageItem

constructor - it seems as though you want a queue of items, but when you

pass a specific itemID, that's what gets posted. Omitting this parameter

will auto-generate an itemID on the server. This would explain the lack of

multiple items, perhaps.

Essentially, I can't tell from your post how far you're getting here. Any

more detail would be useful - for example, what is the "initiation

notification" you're talking about?

nigel

Avatar

Level 2

A) are these methods copied twice in the code here on purpose?
  
connectChat() and onSynchronizationChange is repeated in code due copy paste mistake

B) are both users subscribing to _collectionNode right away? Do each of them

get to onSynchronizationChange?
  
Yes , each of them get to onSynchronizationChange

C) If you put a breakpoint in onSynchronizationChange, do you see the node

get created? Do you see it in the dev console?

Yes , it is creating a node

 

D) Is user B receiving an onItemReceive at all? Is user A?

Yes , it is creating a node

Now both the user getting chat message, have following issue

When user A initiate the chat with user B this action is not opening chat pod / window on user B end which shows user A has initiated chat with user B

But when user B click on user A name to initiate the chat, this action opens a chat window and user B can see message send by user A

Above scenario is not normal chat behavior in which other user gets the notification of chat . what could be the problem