ejabberd add_channel API для MIX

В настоящее время API для создания MIX-канала отсутствует. Я написал собственный модуль для того же самого.

До сих пор я написал следующий код. Но я не знаю, как действовать дальше. Я был бы очень признателен за чье-то руководство здесь. Заранее спасибо.

-module(mod_custom).
-behaviour(gen_mod).
-include("logger.hrl").
-export([start/2, stop/1, reload/3, mod_options/1,
     get_commands_spec/0, depends/2]).
-export([
     % Create channel
     add_channel/4
    ]).

-include("ejabberd_commands.hrl").
-include("ejabberd_sm.hrl").
-include("xmpp.hrl").

start(_Host, _Opts) ->
    ejabberd_commands:register_commands(get_commands_spec()).
stop(Host) ->
    case gen_mod:is_loaded_elsewhere(Host, ?MODULE) of
    false ->
        ejabberd_commands:unregister_commands(get_commands_spec());
    true ->
        ok
    end.
reload(_Host, _NewOpts, _OldOpts) ->
    ok.
depends(_Host, _Opts) ->
    [].

get_commands_spec() ->
    [
        #ejabberd_commands{name = add_channel, tags = [group],
            desc = "Create a WhatsApp like group",
            module = ?MODULE, function = add_channel,
            args = [{jid, binary}, {channel, binary}, {id, binary}],
            args_example = [<<"admin@localhost">>, <<"testgroup123@localhost">>, <<"abc123456">>],
            args_desc = ["Admin JID", "Channel JID", "Unique ID"],
            result = {res, rescode}}
    ].

add_channel(JID, Channel, ID) ->
    %%% Create channel code goes here...
ok.

mod_options(_) -> [].

person Nikhil Supekar    schedule 22.10.2020    source источник


Ответы (1)


Попробуйте что-то вроде этого:

-module(mod_custom).
-behaviour(gen_mod).

-export([start/2, stop/1, reload/3, mod_options/1,
         get_commands_spec/0, depends/2]).
-export([create_channel/3]).

-include("logger.hrl").
-include("ejabberd_commands.hrl").
-include("ejabberd_sm.hrl").
-include_lib("xmpp/include/xmpp.hrl").

start(_Host, _Opts) ->
    ejabberd_commands:register_commands(get_commands_spec()).
stop(Host) ->
    case gen_mod:is_loaded_elsewhere(Host, ?MODULE) of
        false ->
            ejabberd_commands:unregister_commands(get_commands_spec());
        true ->
            ok
    end.
reload(_Host, _NewOpts, _OldOpts) ->
    ok.
depends(_Host, _Opts) ->
    [].

get_commands_spec() ->
    [#ejabberd_commands{name = create_channel, tags = [group],
                        desc = "Create a WhatsApp like group",
                        module = ?MODULE, function = create_channel,
                        args = [{from, binary},
                                {channel, binary},
                                {service, binary}],
                        args_example = [<<"admin@localhost">>,
                                        <<"testgroup123">>,
                                        <<"mix.localhost">>],
                        args_desc = ["From JID", "Channel Name", "MIX Service"],
                        result = {res, rescode}}
    ].

create_channel(From, ChannelName, Service) ->
    try xmpp:decode(
          #xmlel{name = <<"iq">>,
                 attrs = [{<<"to">>, Service},
                          {<<"from">>, From},
                          {<<"type">>, <<"set">>},
                          {<<"id">>, p1_rand:get_string()}],
                 children =
                     [#xmlel{name = <<"create">>,
                             attrs = [{<<"channel">>, ChannelName},
                                      {<<"xmlns">>, ?NS_MIX_CORE_0}]}
                     ]},
          ?NS_CLIENT, []) of
        #iq{type = set} = Iq ->
            case mod_mix:process_mix_core(Iq) of
                #iq{type = result} ->
                    ok;
                _ ->
                    {error, unexpected_response}
            end
    catch _:{xmpp_codec, Why} ->
            {error, xmpp:format_error(Why)}
    end.

mod_options(_) -> [].
person Badlop    schedule 26.10.2020
comment
Спасибо за ответ. Это спасло меня от движения в неправильном направлении. Я вызывал только функцию mod_mix_pam:process_join, не создавая канал. - person Nikhil Supekar; 26.10.2020