
debug=3
log_stderror=yes
memdbg=5
memlog=5

# number of SIP routing processes
children=5

loadmodule "ctl"
loadmodule "tm"
loadmodule "tmx"
loadmodule "sl"
loadmodule "rr"
loadmodule "pv"
loadmodule "textops"
loadmodule "siputils"
loadmodule "xlog"
loadmodule "nathelper"
loadmodule "usrloc"
loadmodule "registrar"
loadmodule "rtp_media_server"
modparam("rtp_media_server", "log_file_name", "/tmp/rms_transfer.log")
modparam("tm", "wt_timer", 1000)
listen=udp:<SET YOUR IP IN kamailio.cfg>:5090

event_route[rms:start] {
	xnotice("[rms:start] play ...\n");
	rms_play("/opt/voice_files/OSR_us_000_0010_8k.wav", "rms:after_play");
};

event_route[rms:bridge] {
	$var(target) = "sip:456@localhost:5069;";
	if (!rms_bridge("$var(target)", "rms:bridged")) {
		send_reply("604", "server error");
		xerr("rtp_media_server bridge error!\n");
		exit;
	}
};

event_route[rms:play_bridge] {
	xnotice("[rms:play_bridge] play ...\n");
	rms_play("/opt/voice_files/OSR_us_000_0010_8k.wav", "rms:bridge");
};

event_route[rms:after_play] {
	xnotice("[rms:after_play] play done...\n");
	rms_hangup();
};

event_route[rms:bridged] {
	xnotice("[rms:bridged] ...\n");
}

event_route[rms:answered] {
	xnotice("[rms:answered] ...\n");
	rms_play("/opt/voice_files/OSR_us_000_0010_8k.wav", "rms:after_play");
}



route {
	if (t_precheck_trans()) {
		t_check_trans();
		exit;
	}
	t_check_trans();

	if (is_method("REGISTER")) {
		save("location");
		exit;
	}

	xnotice("[$rm][$ci]\n");
	if (is_method("INVITE") && !has_totag()) {
		fix_nated_contact();

		if ($rU == "456") {
			rms_answer("rms:play_bridge");
			exit;
		} else if ($rU == "888") {
			$var(target) = "sip:" + $rU + "@8.8.8.8:5069;";
			if (!rms_bridge("$var(target)", "rms:bridged")) {
				send_reply("503", "server error");
				xerr("rtp_media_server bridge error!\n");
			}
			exit;
		}
		if (!rms_answer("rms:answered")) {
			t_reply("503", "server error");
			xerr("rtp_media_server error!\n");
			exit;
		}
	}
	if(rms_dialog_check())
		rms_sip_request();
	exit;
}

