Empty call recording files stored for rejected/unanswered calls

We have a customized soft dialer on a web page which connects to Asterisk for making outbound calls through SIP (pjsip). Both dialer and asterisk reside on separate servers and communicate via wss protocol (https cert installed in Asterisk). We are using MixMonitor to record calls with option b ( b - Only save audio to the file while the channel is bridged). Based on this option, we infer that only when the call is received/answered by Callee, call recordings will be created in the said directory. However, if the callee either does not answer or rejects the call, Mixmonitor is creating 1 kb file but it has not thing in it when played. Is there a way to avoid creating this 1 kb file if the call is not answered.
Below is the extensions.conf excerpt -

[default]
exten => _X.,1,Set(callid=${PJSIP_HEADER(read,call-id)})
same =>n,Dial(PJSIP/${EXTEN}@provider) 
same =>n,MixMonitor(/var/www/html/recordings/${STRFTIME(${EPOCH},,%Y%m%d)}/out-${EXTEN}-${callid}.wav,b)

Current Asterisk version is 17 on CentOS 7. Any pointers on this will greatly help.

Any pointers / suggestions will be greatly appreciated.

If i’m not wrong you must set Dial after MixMonitor.
Try that:

[default]
exten => _X.,1,Set(callid=${PJSIP_HEADER(read,call-id)})
same =>n,Set(RecordName=/var/www/html/recordings/${STRFTIME(${EPOCH},,%Y%m%d)}/out-${EXTEN}-${callid}.wav)
same =>n,MixMonitor(${RecordName},b)
same =>n,Dial(PJSIP/${EXTEN}@provider) 

If it still record an empty file, do a validation at h extension and exclude file:

exten => h,1,ExecIf($["${DIALSTATUS}"!="ANSWER" & ${STAT(f,${RecordName}) ]?System(rm -f ${RecordName}))

It’s a common newbie mistake to think that Dial exits when the number has been dialed.

With it in the current position the OP should also have said the file isn’t created at all if the call is answered! I should have spotted that earlier.

I’m pretty certain it isn’t 125 bytes (1kb). If it appears to be 1KB, I suspect that you are confusing the number of blocks allocated with the actual size. 1KB is the unit in which some filesystems allocate space.

I didn’t mention cleaning up in the h extension, because I wasn’t sure of the exact timing of the close and rename of the file. One of the monitors does rename the file at the end of the recording, but I’m not sure if it is MixMonitor.

Another approach would be to use a Dial subroutine, to only start the MixMonitor on answer, or even use the G option on Dial, to do the same.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.