linphone-developers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Linphone-developers] [LinPhone] App notification for presence received


From: Vicky Dhas
Subject: [Linphone-developers] [LinPhone] App notification for presence received but always offline status given for friend
Date: Wed, 28 May 2014 17:12:02 +0800
User-agent: Microsoft-MacOutlook/14.4.1.140326

Hi Developers,

I have some how managed  to get the notification even from C implement ion to Objective C. But I get the event notification inconsistently in the  notify_presence_received . I am also sending my presence online to all users so to check the presence on other end.

Is there any iOS snippet to show this working. My Code is as given below modified for LinPhone Manager.


static LinphoneCoreVTable linphonec_vtable = {

.show =NULL,

.call_state_changed =(LinphoneCoreCallStateChangedCb)linphone_iphone_call_state,

.registration_state_changed = linphone_iphone_registration_state,

    .notify_presence_received = linphone_notify_presence_received, (This was NULL which I set to this function)

….
}

Overided this function in LinPhone manager referring buddy_status.c

static void linphone_notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf) {

    

    const LinphonePresenceModel* model = linphone_friend_get_presence_model(lf);

const LinphoneAddress* friend_address = linphone_friend_get_address(lf);

LinphonePresenceActivity *activity = linphone_presence_model_get_activity(model);

char *activity_str = linphone_presence_activity_to_string(activity);

printf("New state state [%s] for user id [%s] \n"

           ,activity_str

           ,linphone_address_as_string (friend_address));

    

    

}


Broadcasting the status using these function calls written in LinPhoneManager.m

-(void) linphone_set_status_online

{

    LinphoneCore *lc = [LinphoneManager getLc];

    /*set my status to online*/

linphone_core_set_presence_model(lc, linphone_presence_model_new_with_activity(LinphonePresenceActivityOnline, NULL));

    

}


-(void) linphone_set_status_offline

{

    LinphoneCore *lc = [LinphoneManager getLc];

    /*set my status to online*/

linphone_core_set_presence_model(lc, linphone_presence_model_new_with_activity(LinphonePresenceActivityOffline, NULL));

    

}



Got the call back working using this function written in LinPhoneManager.m 


-(void) linphone_fetch_friends_status:(PersonContact*)personContact

{

    //notify all that we are offline

    [[LinphoneManager instance] linphone_set_status_online];


    

    static bool_t running=TRUE;

    

    //Instantiate LinphoneCore Object

    LinphoneCore *lc = [LinphoneManager getLc];

    

    /*create proxy config*/

    LinphoneProxyConfig* proxy;

    linphone_core_get_default_proxy(theLinphoneCore, &proxy);

    

    /*parse identity*/


    char normalizedUserName[256];

    LinphoneAddress* linphoneAddress = linphone_address_new(linphone_core_get_identity(theLinphoneCore));

    linphone_proxy_config_normalize_number(proxy,[personContact.userSIPId cStringUsingEncoding:[NSString defaultCStringEncoding]],normalizedUserName,sizeof(normalizedUserName));

    linphone_address_set_username(linphoneAddress, normalizedUserName);

    if(personContact.userName!=nil) {

        linphone_address_set_display_name(linphoneAddress, [personContact.userName cStringUsingEncoding:[NSString defaultCStringEncoding]]);

    }

    if ([[LinphoneManager instance] lpConfigBoolForKey:@"override_domain_with_default_one"])

        linphone_address_set_domain(linphoneAddress, [[[LinphoneManager instance] lpConfigStringForKey:@"domain" forSection:@"wizard"] cStringUsingEncoding:[NSString defaultCStringEncoding]]);

    

    if (linphoneAddress==NULL){

        NSLog(@"%@ not a valid sip uri, must be like sip:address@hidden \n",personContact.userSIPId);

    }

    

    /* Loop until registration status is available */

    do {

        linphone_core_iterate(lc); /* first iterate initiates registration */

        ms_usleep(100000);

    }while( running && linphone_proxy_config_get_state(proxy) == LinphoneRegistrationProgress);

    

    const char *address = [[NSString stringWithFormat:@"sip:%@@%@",personContact.userSIPId,kDomain] UTF8String];

    

    NSLog(@"Address of friend : %s",address);

    

    LinphoneFriend* my_friend= linphone_friend_new_with_address(address);

    

    linphone_address_destroy(linphoneAddress);

    

    linphone_friend_enable_subscribes(my_friend,TRUE); /*configure this friend to emit SUBSCRIBE message after being added to LinphoneCore*/

    linphone_friend_set_inc_subscribe_policy(my_friend,LinphoneSPAccept); /* Accept incoming subscription request for this friend*/

    linphone_core_add_friend(lc,my_friend); /* add my friend to the buddy list, initiate SUBSCRIBE message*/

    

    

    /*set my status to online*/

    linphone_core_set_presence_model(lc, linphone_presence_model_new_with_activity(LinphonePresenceActivityOnline, NULL));

    

//    /* main loop for receiving notifications and doing background linphone core work: */

//    while(running){

//        linphone_core_iterate(lc); /* first iterate initiates subscription */

//        ms_usleep(50000);

//    }

//    

    /* change my presence status to offline*/

//    linphone_core_set_presence_model(lc, linphone_presence_model_new_with_activity(LinphonePresenceActivityOffline, NULL));

    linphone_core_iterate(lc); /* just to make sure new status is initiate message is issued */

    

    linphone_friend_edit(my_friend); /* start editing friend */

    linphone_friend_enable_subscribes(my_friend,FALSE); /*disable subscription for this friend*/

    linphone_friend_done(my_friend); /*commit changes triggering an UNSUBSCRIBE message*/

    

    linphone_core_iterate(lc); /* just to make sure unsubscribe message is issued */

    

    

}


Your help is truly appreciated.


Thanks,

Regards,
Vicky Dhas 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]