1 |
|
%% @doc Client State Indication. |
2 |
|
%% |
3 |
|
%% Includes support for XEP-0352: Client State Indication. |
4 |
|
%% |
5 |
|
-module(mod_csi). |
6 |
|
-xep([{xep, 352}, {version, "0.2"}]). |
7 |
|
-behaviour(gen_mod). |
8 |
|
-behaviour(mongoose_module_metrics). |
9 |
|
|
10 |
|
%% gen_mod callbacks |
11 |
|
-export([start/2, |
12 |
|
stop/1, |
13 |
|
config_spec/0, |
14 |
|
supported_features/0]). |
15 |
|
|
16 |
|
%% Hook handlers |
17 |
|
-export([c2s_stream_features/3]). |
18 |
|
|
19 |
|
-ignore_xref([c2s_stream_features/3]). |
20 |
|
|
21 |
|
-include("jlib.hrl"). |
22 |
|
-include("mongoose_config_spec.hrl"). |
23 |
|
|
24 |
|
-type state() :: active | inactive. |
25 |
|
|
26 |
|
-export_type([state/0]). |
27 |
|
|
28 |
|
-spec start(mongooseim:host_type(), gen_mod:module_opts()) -> ok. |
29 |
|
start(HostType, _Opts) -> |
30 |
1 |
ejabberd_hooks:add(hooks(HostType)), |
31 |
1 |
ensure_metrics(HostType), |
32 |
1 |
ok. |
33 |
|
|
34 |
|
-spec stop(mongooseim:host_type()) -> ok. |
35 |
|
stop(HostType) -> |
36 |
1 |
ejabberd_hooks:delete(hooks(HostType)), |
37 |
1 |
ok. |
38 |
|
|
39 |
|
hooks(HostType) -> |
40 |
2 |
[{c2s_stream_features, HostType, ?MODULE, c2s_stream_features, 60}]. |
41 |
|
|
42 |
|
ensure_metrics(HostType) -> |
43 |
1 |
mongoose_metrics:ensure_metric(HostType, [HostType, modCSIInactive], spiral), |
44 |
1 |
mongoose_metrics:ensure_metric(HostType, [HostType, modCSIInactive], spiral). |
45 |
|
|
46 |
|
%%% |
47 |
|
%%% config_spec |
48 |
|
%%% |
49 |
|
|
50 |
|
-spec config_spec() -> mongoose_config_spec:config_section(). |
51 |
|
config_spec() -> |
52 |
166 |
#section{ |
53 |
|
items = #{<<"buffer_max">> => #option{type = int_or_infinity, |
54 |
|
validate = non_negative}}, |
55 |
|
defaults = #{<<"buffer_max">> => 20} |
56 |
|
}. |
57 |
|
|
58 |
|
-spec supported_features() -> [atom()]. |
59 |
|
supported_features() -> |
60 |
:-( |
[dynamic_domains]. |
61 |
|
|
62 |
|
%%% |
63 |
|
%%% Hook handlers |
64 |
|
%%% |
65 |
|
|
66 |
|
-spec c2s_stream_features([exml:element()], mongooseim:host_type(), jid:lserver()) -> |
67 |
|
[exml:element()]. |
68 |
|
c2s_stream_features(Acc, _HostType, _Lserver) -> |
69 |
36 |
lists:keystore(<<"csi">>, #xmlel.name, Acc, csi()). |
70 |
|
|
71 |
|
csi() -> |
72 |
36 |
#xmlel{name = <<"csi">>, |
73 |
|
attrs = [{<<"xmlns">>, ?NS_CSI}]}. |