List of users in current chat room

GLeBaTi
GLeBaTi
edited May 2015 in Photon Chat
Hello. How can i get the list of users in current chat room?

Comments

  • Hi, GLeBaTi
    it is not possible to get users list yet
  • Somehow it's possible, I was planning to write a topic about the same subject.

    I'm asking if there is any way to make it possible to somehow know the other clients "name" at least?

    1) I was able to create list of users by doing like this:
    When user subscribes -> OnSubscribed() -> if successful -> publish empty "" message to that subscribed channel -> other clients hear your message and add your name to a local variable.

    But there is one problem with that. I don't like using this method, because even if the message is empty it's stored inside the subscribed channel's Messages.

    In UI side you can always specify what user can type or not.

    2) I tried before 1) to make the new event, chatclient via server. I used same function structure as in ChatClient.cs and all, I used parameters, I converted data to object etc. But all I managed to receive was in format System.Boolean[]. I only wanted to send new client name info to others, that's all.

    Last but not least, about the PUN. Is there anyway to make a temporary subscriber-provider system that detects new chatclients, if chat client is part of the game in some gameobject. Can PUN send that client name data through network to the other listeners? But that needs to be done inside room right? Or just right away after when photon is connected, not need to be in room yet? There has to be some way to create your own list even manually. Because PhotonChat has way too much good features already that can be used in many ways.

    Any help is welcome.

    (sorry my bad grammar)
  • I will answer only about chat.

    Current idea was to build chat like in game chat. What does this mean? This mean that you create channels according your game logic. For instance team channel, guild channel, or game channel. You know all users how should be inside from other source, not from chat, but from some game logic.
    For big generic chats list of users may be very big and actually not useful. Check for instace WoW. in generic chat you see only messages, but you may iteract with player names right in chat window. List of players removed, because it takes space.
    What are you going to do with this list? take random player and send him message? Why? if he wrote something to chat, good. than you will put him into your list. if he keeps silence, why do you need to write him? if you really need, add him as friend and send private messages.

    What is your scenario? Why do you need this list?
  • Here is my sceanario and why I want a way to get the usernames in a chat:

    My game is turn-based and uses an asynchronous structure for the most part. Recently I updated the game to include a live gameplay mode. Chat has been great as a way to help connect players and let them talk during the matches.

    My online community is very small and it would be awesome to be able to see if *anyone* is online in order to arrange a game. On top of that, in-game chat is only 1-4 people so it would again be nice to see which are online at the same time or to even list their usernames. If you join last, for instance, you don't know who is already in the room and have missed any "joined" type messages.

    I can think of a couple workarounds but they are not ideal.

    Thank you,
    Kris
    @druidsduel
    www.druidsduel.com
  • Thank you for your sharing.

    We will think about it
  • This is a must feature for chat, Photon Chat should include it!
    Implementing this on client side results in a lot of hidden messages for sync and history messages lost for new connections.
    Is planned to be available in future?
  • yes
  • Hello
    How can i add rooms within a specific channel. And it one to be global and two private.
    If you provide me with an example i will appreciate

    Thanks
  • there is no such functionality in our sdk. I believe that what you described should be implemented on client. i mean that you just create global channel and private channels and than represent them in your client in a way you need
  • I'm in a similar situation. Game is in alpha state, so very small player base. And it's sync multiplayer, so people use my channel "Global" to talk to people and see if anyone is there and wants to start a match. Currently, they cannot see who else is online and in the chat room.

    1. Is there any updates or progress on this? (i.e getting a list or channel subscribers)
    2. If I still can not list all players in my "Global" channel, is there a way I can at least get the number of players in the channel?
    3. If none of the above is possible, what's the best current workaround?

    Assuming "3":

    One workaround I've been thinking of is having the player automatically joining an "invisible" parallel channel called "GlobalSubscribers". All players automatically send an empty message in that channel every minute or so, and the receiving clients keep track of these messages by holding the sender names and the latest timestamp in a list or dictionary or something, and as such can keep a realitively updated list.

    Any other ideas?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @Bankler,

    1. We have added a new feature of publishing susbcription and unsubscription events along with previous list of subscribers. This is currently being tested. I cannot give you an ETA but I will ask if we can arrange an early access somehow. I'm not promising anything though.
    2. I will check and see if this is possible and get back to you.
    3. Your workaround is good but I wonder why you did not make use of the Status channel in combination with AddFriends. So here is how I see it:

    Each client needs a list of userIDs. This can be obtained using your "GlobalSubscribers" channel and a cached list.
    Call AddFriends using that array of userIDs (max allowed is 512).
    Every user needs to set his status using SetOnlineStatus and anyone who has added him as a friend will receive the status update.
  • Hello,

    Getting a list of users in the current chat room is a must have for multiple reasons..

    1 : Would you start talking in a room if you don't know the number of people in that room?

    2 : Not being able to add someone in your friend list if he hasn't talked on the chat yet is a big issue.

    3 : When you join a private room with your friends you want to know who is in the room already.

    4 : For big generic chat with a huge list of users just let us handle that on the client side. We can just display the user count instead of each individual users.


    Is it that complicated to implement on your side?

    This is really a must have feature, please consider giving us the option to get the number of users in a channel, that would improve the chat considerably.


    Regards
  • Jay_mt said:

    Hello,

    Getting a list of users in the current chat room is a must have for multiple reasons..

    1 : Would you start talking in a room if you don't know the number of people in that room?

    2 : Not being able to add someone in your friend list if he hasn't talked on the chat yet is a big issue.

    3 : When you join a private room with your friends you want to know who is in the room already.

    4 : For big generic chat with a huge list of users just let us handle that on the client side. We can just display the user count instead of each individual users.


    Is it that complicated to implement on your side?

    This is really a must have feature, please consider giving us the option to get the number of users in a channel, that would improve the chat considerably.


    Regards

    Totally agree with this. Any chance of being able to get a list of current chat room users soon?
  • Legend
    Legend
    edited May 2018
    Hi i solved this problem with this logic:

    User: Some123

    [Message as notification]
    1. When a Some123 has been connected, he will send one automatic message in the channel.
    This message can be any that you want, like "#Code 400#"
    And this message will be sended in the OnSubscribed method for EVERY SUBSCRIBED CHANNEL from the ChatGui code.

    DON'T show this message in the channel text, it will be used internally only.
    (with this all other users in the channel will be notificated although they are not friends)
    public void OnSubscribed(string[] channels, bool[] results)
    {
    	foreach (string channel in channels)
    	{
    	    if (this.ChannelToggleToInstantiate != null)
    	    {
    		this.InstantiateChannelButton(channel);
                    
                    chatClient.PublishMessage(channel, "#Code 400#");
    
                    // CODE OF THIS METHOD BELOW
                    StartCoroutine(GetOnlineUsersFromChannel(channel));
                }
    	}
    	
    	// Switch to the first created channel to update it
    	ShowChannel("General"); // PLEASE CHANGE "General" to YOUR PRIMARY CHANNEL NAME
     }
    Here you need to create a method that will be called in 1 second after sending the automatic message.
    IEnumerator GetOnlineUsersFromChannel (string channelName)
    {
            yield return new WaitForSeconds(1f);
    
            ChatChannel chatChannel;
            chatClient.TryGetChannel(channelName, out chatChannel);
    
            // Get usernames
            var usersList = chatChannel.Senders.Distinct().ToList();
    
            AddMessageToChannel(string.Format("Connected users in this channel: {0}", usersList.Count), channelName);
     
            // Update the current channel
            if (channelName == selectedChannelName) {
                ShowChannel(channelName);
            }
    
            yield return null;
    }
    [All users has been notificated]
    2. All others users will receive a message from the new connected user Some123 "#Code 400#".
    Remember, this message is not showed in the channel text.

    [These users will notify the new user that they are connected!]
    3. All users in the room that received that message will send another key message like "#Code 401#"

    DON'T show this message too, it is only for internal use.

    This message will be sended from OnGetMessage
    public void OnGetMessages(string channelName, string[] senders, object[] messages)
    {
            // Analyze messages for any "special code"
            for (int i = 0; i < messages.Length; i++) {
                  if (messages[i].ToString() == "#Code 400#") {
                      chatClient.PublishMessage (channelName, "#Code 401#");
                  }
             }
    
            // Update text if the new message is for the selected channel
    	if (channelName.Equals(this.selectedChannelName))
    	{
    		// Update text
    		ShowChannel(this.selectedChannelName);
    	}
    }
    [The new user are notificated]
    4. Some123 will receive a message from all others users from the room.

    [Get user list]
    5. After 1 second, all other users have sent their message, so you can count it now, GetOnlineUsersFromChannel is called.
    (that's why i waited 1 second in the step one)


    What if some user send that exact message from that chat???
    ... Omg what you can do?
    If a user types that message, ignore it in the code
    if (message == "myCode") {
        return;
    }

    Remember, GetOnlineUsersFromChannelList users are only updated when a user has subscribed to the channel; If you want to obtain an updated list when a user disconnects or cancels the channel subscription, you must add the notification in their respective methods.


    Good luck, and please follow my game!

    https://facebook.com/lyniumGame/
    http://lyniumgame.com/
  • JohnTube said:


    1. We have added a new feature of publishing susbcription and unsubscription events along with previous list of subscribers. This is currently being tested. I cannot give you an ETA but I will ask if we can arrange an early access somehow. I'm not promising anything though.

    Is this available yet as it would be very useful?

    We are currently using the Pun Private Chat system as a means to instantly send invites to games from Friends and also to send Friend requests. We are using PlayFab to store the list of friends.

    Users will be able to make friend requests from players they meet in online matches. This is easily implemented as both players will be logged into chat at the time.

    We also want to make functionality to allow friends to add each other by simply typing in their unique name. This needs to be with the friends consent so it doesn't cause social issues.

    If both players are online one player can send the other player a friend request, which works fine. But if the one player is not online here is where we could use a function that checks if a user name is currently connected to chat.

    So we would need a method that Checks if a user is connected to chat.

    Then the calls would go...

    Check if player connected to chat. If connected send the request. If not connected then send the request to their PlayFab account so they will get the request next time they log in.

    PlayFab doesn't instant messaging and that is why we are using Photon Chat.

    Currently we can send a Private Message to a user but is there a way to check if the user exists/connected and received the message?


  • Legend said:

    Hi i solved this problem with this logic:
    What if some user send that exact message from that chat???
    ... Omg what you can do?
    If a user types that message, ignore it in the code

    if (message == "myCode") {
        return;
    }
    /
    Thanks @Legend for this suggestion. I may end up using something similar. I just wanted to note that since the message sent is of type object you can create a new Message class and convert it to a JSON string then at OnGetMessages convert it back to your message class. Now you can use your custom message class variables to determine if the message is a "system message" used internally or a message sent by players to read.

    An example message class:
    public class CTPrivateMessage
    {
        public bool request;
        public string message;
        public string messageType;
    
        public CTPrivateMessage(string mesg, bool req, string msgType)
        {
            request = req;
            messageType = msgType;
            message = mesg;
        }
    }
  • Is there any updates on this?? Can't we really know the list of users subscribed? It is a real pain to not know. The fix listed here is not really usefull, because It doesn't take in account the fact that any user can disconnect at any time with no prior notice (e.g. network gone, window closed). Are you planning on allowing us to retrieve the connected users ? this is really a must.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @masterkitano,

    Thank you for choosing Photon!

    Currently, we have this as an experimental early access feature.
    It is only available for C#/.Net/Unity SDKs.
    Send an email to developer@photonengine.com if you want in.
  • Thank you for the fast response! I'll reach out to that email to request the access.
  • JohnTube
    JohnTube ✭✭✭✭✭
    hey guys, good news.
  • Great news indeed! Thanks for this! I tested the subscribers list in Unity and it works.

    I have two questions:

    1. When the channel is created, the user is not in the list of subscribers. If there are others in the channel and I as the creator unsubscribe an re-subscribe, then I am on the list. Is there any way the creator can be on the list from the start?
    2. When will this be available in the Javascript api?

    Cheers!
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited February 2019
    Hi @roryone,

    Thank you for choosing Photon!

    1. The server does not return the subscribed user (local user) in the subscribers' list, only those previously subscribed. However, locally we add the user to the list of subscribers, do you see a different behaviour? So the creator should be on the list from the start. I will investigate the behaviour when the "creator unsubscribe an re-subscribe".
    2. soon, we're working on it, no ETA sorry. If you have a tight schedule let us know by email to developer@photonengine.com
  • Ok - thanks for the explanation (and the quick response!). No need to "investigate the behaviour when the "creator unsubscribe an re-subscribe". That was just an idea I was playing with to get the creator on the list. I am now just adding the creator in Connect().