[Objective C SDK] Room Properties Event, the changes(nsdictionary) is always null.

zaki
zaki
edited August 2015 in Native
Hello,

I downloaded and using: Photon-iOS-Sdk_v4-0-4-0, tested:
demo_loadBalancing_objc and demo_loadBalancing_swift

I modify the sendEvent function in NetworkLogic.mm (obj c)
- (void) sendEvent
{
    static int64 count;
    NSDictionary * props = [[NSDictionary alloc] initWithObjectsAndKeys:@"hello", @"test", nil];
    [[mLoadBalancingClient CurrentlyJoinedRoom] mergeCustomProperties:props];
    
    [mLoadBalancingClient opRaiseEvent:true :[NSValue valueWithBytes:&++count objCType:@encode(int64)] :EGEventCode_PROPERTIES_CHANGED :0 :EGEventCache_DO_NOT_CACHE :NULL :0 :EGReceiverGroup_ALL];
}
Then added this:
- (void) onRoomPropertiesChange:(NSDictionary*)changes
{
    NSLog(@"room properties changed: %@", changes);
}
The "changes" always null.

Comments

  • zaki
    zaki
    edited August 2015
    hmm.. Sorry guys, i could not edit the title of this post.

    The title should be: [Objective C SDK] Room Properties Event, the changes(nsdictionary) is always null.

    I hope the forum admin can edit for me. Thanks
  • I edited the topic (no problem).
    Our "Native Client Guru" is currently on vacation and will get back to this topic next week. Sorry for the delay.
  • Hi zaki.
    - (void) sendEvent
    {
        [mLoadBalancingClient opRaiseEvent:true :[NSValue valueWithBytes:&++count objCType:@encode(int64)] :EGEventCode_PROPERTIES_CHANGED :0 :EGEventCache_DO_NOT_CACHE :NULL :0 :EGReceiverGroup_ALL];
    }
    That code sends a raiseEvent operation to the server, which instructs the server to send an event with the specified payload to the specified clients. As payload that code specifies 'count', as receivers everyone in the room including the sender ('EGReceiverGroup_ALL') and as event code 'EGEventCode_PROPERTIES_CHANGED'.

    Unfortunately 'EGEventCode_PROPERTIES_CHANGED' is a predefined event code used by Photon internally to propagate room property changes to other clients.

    When a Photon Client receives an event that includes this code it expects the event to contain the room property change data in a certain format. The LoadBalancing Client then passes this data to the onPropertiesChange() callback and also merges that change into the local representation of the room properties.

    As you have not added the room properties to payload of opRaiseEvent() they are not contained in that event and the receiving client doesn't receive anything that it could pass to the callback.

    You should not use any event codes yourself that are predefined by Photon to avoid conflicts between custom events of the app and built-in events of Photon.
    Assign codes starting from 0 upwards for you own events and avoid codes above 200 as those are used by Photon itself.

    You don't need to call opRaiseEvent at all for updating room properties.
    Instead the call to mergeCustomproperties() is all you need.
    The setter of that property will automatically trigger a room property change operation that will get sent out with the next service() call and trigger a call to onRoomPropertiesChange() on remote clients (it does not get called for the local client as that one already knows about the changes that it has done itself)

    However your testcode might not be ideal for testing as your props dictionary has always identical content, so that mergeCustomproperties() can't see any changes after the first call and later calls therefor won't trigger any further updates.

    Without further modificactions of the demo it's nearly impossible to not miss the first call. The client that creates the room will immediately trigger the update and as it has triggered it itself, it won't receive a call to the callback. Other clients will have a very hard time to join the room before the creating client has already triggered the update, so they will miss the change and get the already changes room properties roon entering the room, so that there is never a change for them in the first place. So they won't receive a call to the callback either.

    To solve this issue, you could modify the testcode to change the properties to something else with every call.

    For example you could change the line in which you set the props NSDictionary to the following code:
    - (void) sendEvent
    {
        NSDictionary * props = [[NSDictionary alloc] initWithObjectsAndKeys:[NSString stringWithFormat:@"hello%lld", ++count], @"test", nil];
    }
    That way every call to mergeCustomProperties() will set the value of the @test property to a different string and therefor trigger a call to onRoomPropertiesChange().
  • Hello Kaiserludi,

    Thanks for the explanation. After tested your codes, it works.