如何使用 Freeswitch 和 Jitsi 设置 SIP 电话会议

How Do I set up SIP Conference Calls With Freeswitch and Jitsi

我正在尝试配置我的 freeswitch 实例以将呼叫路由到 Jitsi meet 并加入会议。我该如何设置?

我创建了一个 lua 脚本,它将接听电话并询问会议代码并将电话重定向到正确的 jitsi 会议。该脚本将使用用户输入的会议号码调用会议网络 api,并直接桥接正确会议的呼叫。

--This script goes in the scripts folder for freeswitch.  The default location of that folder is /usr/share/freeswitch/scripts/
local function buildGetConverenceByIdRequest(conferenceId)
  --This url should match what is set in /etc/jitsi/meet/config.js in the dialInConfCodeUrl.
  --In this case I used the api.jitsi.net one, but you could build your own.
  return string.format('https://api.jitsi.net/conferenceMapper?id=%s', conferenceId);
end

--Pass in the domain as the first argument in the extenson xml.
local domain = argv[1]; 

local request = require 'http.request'
local cjson = require 'cjson'
local cjson2 = cjson.new();
 
attempt = 1
max_attempts = 3
 
function session_hangup_hook(status)
  freeswitch.consoleLog("NOTICE", "Session hangup: " .. status .. "\n")
  error()
end
 
function get_conference_num(min, max, attempts, timeout)
  local conference_num = "";
  freeswitch.consoleLog("NOTICE", "Awaiting caller to enter a conference number phrase:conference_num\n");
  -- conference_num = session:playAndGetDigits(min, max, attempts, timeout, '#', 'phrase:conference_num', '', '\d+');
  conference_num = session:playAndGetDigits(min, max, attempts, timeout, '#', 'conference/8000/conf-enter_conf_number.wav', '', '\d+');
  return(conference_num);
end
 
session:answer();
session:setHangupHook("session_hangup_hook");
 
if session:ready() then
  freeswitch.consoleLog("NOTICE", string.format("Caller has called conferencing server, Playing welcome message phrase:conference_welcome\n"));
  --session:execute("phrase", "conference_welcome");
  session:execute("playback", "conference/8000/conf-welcome.wav");
end
 
while attempt <= max_attempts and session:ready() do
  local conf_num = get_conference_num(1, 20, 3, 4000);
  local getConferenceUrl = buildGetConverenceByIdRequest(conf_num);
  freeswitch.consoleLog("NOTICE", string.format("Conference url: %s", getConferenceUrl));
  local headers, stream = assert(request.new_from_uri(getConferenceUrl):go());
  local body = assert(stream:get_body_as_string());

  local status = headers:get ":status";
  if status ~= "200" then
    --something went wrong
    freeswitch.consoleLog("NOTICE", string.format("Unable to access conference code service.  Error code: %s", status))
    session:execute("speak", "flite|slt|Unable to access the conference system.  Please try again later.");
    attempt = max_attempts;
    break;
end
local responseObject = cjson.decode(body);
if responseObject.conference then --nil or false evaluates to false, so if there is a conference, this code will catch it.
    --invalid conference number.  Please try again.
    freeswitch.consoleLog("NOTICE", string.format("Found matching conference: %s", responseObject.conference));
    local conferenceFoundSentence = string.format("flite|slt|We found your conference %s", responseObject.conference);
    --todo:  remove this speaking here once the conference joining is worked out.
    -- session:execute("speak", conferenceFoundSentence);
    local conferenceHeader = string.format("sip_h_X-Room-Name=%s", responseObject.conference);

    session:execute("set", conferenceHeader);
    local userAddress = string.format("user/jitsiSipUser@%s", domain);
    session:execute("bridge", userAddress);
    break;
  else 
    --[[ if the conference number does not exist, playback message saying it is
    and invalid conference number ]]--
    -- session:execute("phrase", "conference_bad_num");
    -- session:execute("speak", "flite|slt|The conference number you entered is not valid.");
    -- session:execute("playback", "misc/8000/invalid_extension");
    -- session:execute("playback", "directory/8000/dir-please_try_again");
    session:execute("playback", "ivr/8000/ivr-please_check_number_try_again");
  end  
  
  attempt = attempt + 1;
end

-- session:execute("phrase", "conference_too_many_failures");
-- session:execute("speak", "flite|slt|You entered the incorrect pin too many times.");
session:execute("playback", "ivr/8000/ivr-access_denied.wav");

session:hangup();

要使用此脚本,您需要创建如下拨号方案:

 <extension name="conference_jitsi">
  <condition field="destination_number" expression="^[number reserved for jitsi]$">
    <action application="lua" data="conference_management_jitsi_http.lua ${domain}"/>
  </condition>
</extension>

在 jitsi 社区中查看此主题:https://community.jitsi.org/t/jitsi-meet-jigasi-freeswitch/29556/32