Why the c program does not work?Event-Name is allways "SOCKET_DATA"
Hi! I'm new user to freeswitch.I write a c program to dial and play a wav file. I want to know hangup-cause.But it does not work.The Event-Name i got is "SOCKET_DATA" not "CHANNEL_HANGUP". Can you help me to fix it and get hangup-cause? Then i will dial lot of number but only on work time (9:00-11:00,14:00-17:00).So I want to use crontab to send custom event to crotrol dial start or stop.So how to send and receive custom event ? Beside the crotab and custom event,any other better idea to control when to start or stop ? Thanks! #include <stdio.h> #include <stdlib.h> #include <esl.h> int main(void) { esl_handle_t handle = {{0}}; esl_status_t status1,status2,status3; int done = 0; esl_status_t status; time_t exp = 0; //esl_global_set_default_logger(7); status1 = esl_connect(&handle, "localhost", 8021, NULL, "ClueCon"); esl_events(&handle, ESL_EVENT_TYPE_PLAIN, "CHANNEL_ANSWER CHANNEL_ORIGINATE CHANNEL_HANGUP"); status2 = esl_send_recv(&handle, "api originate user/1001 &playback(/tmp/a.wav)\n\n"); if (handle.last_sr_event && handle.last_sr_event->body) { printf("Sucess --- %s\n", handle.last_sr_event->body); } else { // this is unlikely to happen with api or bgapi (which is hardcoded above) but prefix but may be true for other commands printf("Fail --- %s\n", handle.last_sr_reply); } while((status = esl_recv_event(&handle, 1,NULL)) != ESL_FAIL) { if (status == ESL_SUCCESS) { char *type = esl_event_get_header(handle.last_event, "content-type"); printf("--- %s\n", type); printf("--- %s\n",esl_event_get_header(handle.last_event, "Event-Name")); //next to get Hangup-Cause from Event-Name:CHANNEL_HANGUP } } esl_disconnect(&handle); return 0; } [freeswitch@fs ~]$ ./test Sucess --- +OK 3fe60603-0ed4-4a6d-9322-dd906433b3cc --- text/event-plain --- SOCKET_DATA --- text/event-plain --- SOCKET_DATA --- text/event-plain --- SOCKET_DATA --- text/event-plain --- SOCKET_DATA
participants (1)
-
Alex Zhou