use OpRaiseEvent to send private message

Hi guy, I am working on a project need photon client both on DoNet platform and Android platform, but when I found that the OpRaiseEvent in C# has the function of sending message to designated users, which is
peer.OpRaiseEvent((byte)OperationCode.PrivateChatOperation, evData, true, 0, users);
But When I use this interface in Android, It hints that the arguments are not applicable! And I looked up the Android document, which defines this interface like this:
opRaiseEvent
public short opRaiseEvent(byte eventCode,
                          Hashtable<Object,Object> evData,
                          boolean sendReliable)

public short opRaiseEvent(byte eventCode,
                          Hashtable<Object,Object> evData,
                          boolean sendReliable,
                          byte channelId)
And neither has the last argument to designate users like in C#.

Is there any other way to use this function, or the Android does not implement the interface this way at all?

PS: I am using the Photon 2.6 and connecting to Lite server.

Thanks!

Comments

  • Hi.
    Sorry, but the Android Photon 2 clients don't support this feature out of the box.
    You basically have 2 options:
    a) Switch to Photon 3.
    b) Add this functionality to the Photon 2 client yourself, based on PhotonPeer.OpCustom()
    For b) the following code should work:
    public short opRaiseEvent(byte eventCode, Hashtable<Object, Object> evData, boolean sendReliable, byte channelId, int[] targetActors)
    {
    	if (evData == null) 
    	{
    		evData = new Hashtable<Object, Object>();
    	}
    	final Hashtable<Byte, Object> wrap = new Hashtable<Byte, Object>();
    	wrap.put(LiteOpKey.Data.value(), evData);
    	wrap.put(LiteOpKey.Code.value(), eventCode);
    	if (targetActors != null)
    	{
    		wrap.put((byte)11, targetActors);
    	}
    	return opCustom(LiteOpCode.RaiseEvent, wrap, sendReliable, channelId, false);
    }
    
  • Thanks for your solutions.

    About the solution b, it looks like you just changed the the code of LitePeer class, but this class is added from the photon-android.jar package, no source code is provided, so how can I rewrite this opRaiseEvent method outside the LitePeer class? It seems not able to be overrode.

    I consider just call the opCustom directly, do you think this is a good choice?
  • billTCP wrote:
    Thanks for your solutions.

    About the solution b, it looks like you just changed the the code of LitePeer class, but this class is added from the photon-android.jar package, no source code is provided, so how can I rewrite this opRaiseEvent method outside the LitePeer class? It seems not able to be overrode.

    I consider just call the opCustom directly, do you think this is a good choice?
    My intention has been, not to override it, but to inherit from LitePeer and then add the code from my previous post as an overload for this method.
    Alternatively you could just add this method to some of you classes, but then you would have to make the peer available to it, so you can call opCustom on the peer.
    However I would wrap this code away in a method either way, instead of just calling opCustom directly everywhere in your code, where you call opRaiseEvent, just to avoid the redundancy of copy- and pasting the code.
  • I think I got your point. You mean that I should create a class of my own in the project, for example, named myLitePeer, and this class is a subclass of the standard LitePeer, containing a new method(overload of the opRaiseEvent with the parameter targetActors) which can meet my requirement. And wherever I need LitePeer, I use myLitePeer instead, is that true?
  • Exactly

    That makes it easier for you to do it and on top of it allows you to much easier update your photon version later on