Changeset 269


Ignore:
Timestamp:
Mar 2, 2006 9:19:55 PM (18 years ago)
Author:
bennylp
Message:

Added IM and composition indication, and tested

Location:
pjproject/trunk/pjsip-apps
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/build

    • Property svn:ignore
      •  

        old new  
        22*.opt 
        33*.plg 
         4*.log 
        45.* 
  • pjproject/trunk/pjsip-apps/src/pjsua/main.c

    r258 r269  
    8484 * Notify UI when invite state has changed. 
    8585 */ 
    86 void pjsua_ui_inv_on_state_changed(int call_index, pjsip_event *e) 
     86void pjsua_ui_on_call_state(int call_index, pjsip_event *e) 
    8787{ 
    8888    pjsua_call *call = &pjsua.calls[call_index]; 
     
    111111 * Notify UI when registration status has changed. 
    112112 */ 
    113 void pjsua_ui_regc_on_state_changed(int code) 
    114 { 
    115     PJ_UNUSED_ARG(code); 
     113void pjsua_ui_on_reg_state(int acc_index) 
     114{ 
     115    PJ_UNUSED_ARG(acc_index); 
    116116 
    117117    // Log already written. 
     118} 
     119 
     120 
     121/** 
     122 * Incoming IM message (i.e. MESSAGE request)! 
     123 */ 
     124void pjsua_ui_on_pager(int call_index, const pj_str_t *from,  
     125                       const pj_str_t *to, const pj_str_t *text) 
     126{ 
     127    /* Note: call index may be -1 */ 
     128    PJ_UNUSED_ARG(call_index); 
     129    PJ_UNUSED_ARG(to); 
     130 
     131    PJ_LOG(3,(THIS_FILE,"MESSAGE from %.*s: %.*s", 
     132              (int)from->slen, from->ptr, 
     133              (int)text->slen, text->ptr)); 
     134} 
     135 
     136 
     137/** 
     138 * Typing indication 
     139 */ 
     140void pjsua_ui_on_typing(int call_index, const pj_str_t *from, 
     141                        const pj_str_t *to, pj_bool_t is_typing) 
     142{ 
     143    PJ_UNUSED_ARG(call_index); 
     144    PJ_UNUSED_ARG(to); 
     145 
     146    PJ_LOG(3,(THIS_FILE, "IM indication: %.*s %s", 
     147              (int)from->slen, from->ptr, 
     148              (is_typing?"is typing..":"has stopped typing"))); 
    118149} 
    119150 
     
    309340        result->nb_result = atoi(buf); 
    310341 
    311         if (result->nb_result > 0 && result->nb_result <= (int)pjsua.buddy_cnt) { 
    312             --result->nb_result; 
     342        if (result->nb_result >= 0 && result->nb_result <= (int)pjsua.buddy_cnt) { 
     343            result->nb_result; 
    313344            return; 
    314345        } 
     
    369400    char menuin[10]; 
    370401    char buf[128]; 
     402    char text[128]; 
    371403    int i, count; 
    372404    char *uri; 
     
    388420            printf("(You currently have %d calls)\n", pjsua.call_cnt); 
    389421             
     422            uri = NULL; 
    390423            ui_input_url("Make call", buf, sizeof(buf), &result); 
    391424            if (result.nb_result != NO_NB) { 
    392                 if (result.nb_result == -1) 
     425 
     426                if (result.nb_result == -1 || result.nb_result == 0) { 
    393427                    puts("You can't do that with make call!"); 
    394                 else 
    395                     pjsua_make_call( current_acc,  
    396                                      pjsua.buddies[result.nb_result].uri.ptr,  
    397                                      NULL); 
    398             } else if (result.uri_result) 
    399                 pjsua_make_call( current_acc, result.uri_result, NULL); 
     428                    continue; 
     429                } else { 
     430                    uri = pjsua.buddies[result.nb_result-1].uri.ptr; 
     431                } 
     432 
     433            } else if (result.uri_result) { 
     434                uri = result.uri_result; 
     435            } 
    400436             
     437            pjsua_make_call( current_acc, uri, NULL); 
    401438            break; 
    402439 
     
    414451            ui_input_url("Make call", buf, sizeof(buf), &result); 
    415452            if (result.nb_result != NO_NB) { 
    416                 if (result.nb_result == -1) { 
     453                if (result.nb_result == -1 || result.nb_result == 0) { 
    417454                    puts("You can't do that with make call!"); 
    418455                    continue; 
    419456                } 
    420                 uri = pjsua.buddies[result.nb_result].uri.ptr; 
     457                uri = pjsua.buddies[result.nb_result-1].uri.ptr; 
    421458            } else { 
    422459                uri =  result.uri_result; 
     
    430467                    break; 
    431468            } 
     469            break; 
     470 
     471        case 'i': 
     472            /* Send instant messaeg */ 
     473 
     474            /* i is for call index to send message, if any */ 
     475            i = -1; 
     476     
     477            /* Make compiler happy. */ 
     478            uri = NULL; 
     479 
     480            /* Input destination. */ 
     481            ui_input_url("Send IM to", buf, sizeof(buf), &result); 
     482            if (result.nb_result != NO_NB) { 
     483 
     484                if (result.nb_result == -1) { 
     485                    puts("You can't send broadcast IM like that!"); 
     486                    continue; 
     487 
     488                } else if (result.nb_result == 0) { 
     489     
     490                    i = current_call; 
     491 
     492                } else { 
     493                    uri = pjsua.buddies[result.nb_result-1].uri.ptr; 
     494                } 
     495 
     496            } else if (result.uri_result) { 
     497                uri = result.uri_result; 
     498            } 
     499             
     500 
     501            /* Send typing indication. */ 
     502            if (i != -1) 
     503                pjsua_call_typing(i, PJ_TRUE); 
     504            else 
     505                pjsua_im_typing(current_acc, uri, PJ_TRUE); 
     506 
     507            /* Input the IM . */ 
     508            if (!simple_input("Message", text, sizeof(text))) { 
     509                /* 
     510                 * Cancelled. 
     511                 * Send typing notification too, saying we're not typing. 
     512                 */ 
     513                if (i != -1) 
     514                    pjsua_call_typing(i, PJ_FALSE); 
     515                else 
     516                    pjsua_im_typing(current_acc, uri, PJ_FALSE); 
     517                continue; 
     518            } 
     519 
     520            /* Send the IM */ 
     521            if (i != -1) 
     522                pjsua_call_send_im(i, text); 
     523            else 
     524                pjsua_im_send(current_acc, uri, text); 
     525 
    432526            break; 
    433527 
     
    576670 
    577671                if (result.nb_result != NO_NB) { 
    578                     if (result.nb_result == -1)  
     672                    if (result.nb_result == -1 || result.nb_result == 0) 
    579673                        puts("You can't do that with transfer call!"); 
    580674                    else 
    581675                        pjsua_call_xfer( current_call, 
    582                                          pjsua.buddies[result.nb_result].uri.ptr); 
     676                                         pjsua.buddies[result.nb_result-1].uri.ptr); 
    583677 
    584678                } else if (result.uri_result) { 
     
    638732                    for (i=0; i<pjsua.buddy_cnt; ++i) 
    639733                        pjsua.buddies[i].monitor = (menuin[0]=='s'); 
     734                } else if (result.nb_result == 0) { 
     735                    puts("Sorry, can only subscribe to buddy's presence, " 
     736                         "not from existing call"); 
    640737                } else { 
    641                     pjsua.buddies[result.nb_result].monitor = (menuin[0]=='s'); 
     738                    pjsua.buddies[result.nb_result-1].monitor = (menuin[0]=='s'); 
    642739                } 
    643740 
     
    671768            pjsua.acc[current_acc].online_status =  
    672769                !pjsua.acc[current_acc].online_status; 
     770            printf("Setting %s online status to %s\n", 
     771                   pjsua.acc[current_acc].local_uri.ptr, 
     772                   (pjsua.acc[current_acc].online_status?"online":"offline")); 
    673773            pjsua_pres_refresh(current_acc); 
    674774            break; 
     
    741841 
    742842        default: 
     843            if (menuin[0] != '\n' && menuin[0] != '\r') { 
     844                printf("Invalid input %s", menuin); 
     845            } 
    743846            keystroke_help(); 
    744847            break; 
Note: See TracChangeset for help on using the changeset viewer.