Skip to content

Commit

Permalink
#88: add XMPP ping settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Oct 31, 2020
1 parent 43d04f5 commit 41b656c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
5 changes: 4 additions & 1 deletion Emulsion.Tests/SettingsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ let private testConfigText groupIdLiteral =
""password"": ""password"",
""room"": ""room"",
""nickname"": ""nickname"",
""messageTimeout"": ""00:00:30""
""messageTimeout"": ""00:00:30"",
""pingTimeout"": ""00:00:30""
},
""telegram"": {
""token"": ""token"",
Expand All @@ -36,6 +37,8 @@ let private testConfiguration = {
RoomPassword = None
Nickname = "nickname"
MessageTimeout = TimeSpan.FromSeconds 30.0
PingInterval = None
PingTimeout = TimeSpan.FromSeconds 30.0
}
Telegram = {
Token = "token"
Expand Down
2 changes: 2 additions & 0 deletions Emulsion.Tests/Xmpp/EmulsionXmppTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ let private settings = {
RoomPassword = None
Nickname = "nickname"
MessageTimeout = TimeSpan.FromSeconds 30.0
PingInterval = None
PingTimeout = defaultPingTimeout
}

let private runClientSynchronously settings logger client onMessage =
Expand Down
2 changes: 1 addition & 1 deletion Emulsion/Emulsion.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="EmulsionSettings.fs" />
<Compile Include="Settings.fs" />
<Compile Include="Message.fs" />
<Compile Include="MessageSender.fs" />
<Compile Include="MessageSystem.fs" />
Expand Down
20 changes: 15 additions & 5 deletions Emulsion/EmulsionSettings.fs → Emulsion/Settings.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type XmppSettings = {
RoomPassword: string option
Nickname: string
MessageTimeout: TimeSpan
PingInterval: TimeSpan option
PingTimeout: TimeSpan
}

type TelegramSettings = {
Expand All @@ -30,6 +32,16 @@ type EmulsionSettings = {
}

let defaultMessageTimeout = TimeSpan.FromMinutes 5.0
let defaultPingTimeout = TimeSpan.FromSeconds 30.0

let private readTimeSpanOpt key (section: IConfigurationSection) =
section.[key]
|> Option.ofObj
|> Option.map (fun s -> TimeSpan.Parse(s, CultureInfo.InvariantCulture))

let private readTimeSpan defaultVal key section =
readTimeSpanOpt key section
|> Option.defaultValue defaultVal

let read (config : IConfiguration) : EmulsionSettings =
let readXmpp (section : IConfigurationSection) = {
Expand All @@ -38,11 +50,9 @@ let read (config : IConfiguration) : EmulsionSettings =
Room = section.["room"]
RoomPassword = Option.ofObj section.["roomPassword"]
Nickname = section.["nickname"]
MessageTimeout =
section.["messageTimeout"]
|> Option.ofObj
|> Option.map (fun s -> TimeSpan.Parse(s, CultureInfo.InvariantCulture))
|> Option.defaultValue defaultMessageTimeout
MessageTimeout = readTimeSpan defaultMessageTimeout "messageTimeout" section
PingInterval = readTimeSpanOpt "pingInterval" section
PingTimeout = readTimeSpan defaultPingTimeout "pingTimeout" section
}
let readTelegram (section : IConfigurationSection) = {
Token = section.["token"]
Expand Down
18 changes: 17 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,23 @@ $ dotnet build
Configure
---------

Copy `emulsion.example.json` to `emulsion.json` and set the settings.
Copy `emulsion.example.json` to `emulsion.json` and set the settings. For some
settings, there're defaults:

```json
{
"xmpp": {
"roomPassword": null,
"messageTimeout": "00:05:00",
"pingInterval": null,
"pingTimeout": "00:00:30"
}
}
```

All the other settings are required.

Note that `pingInterval` of `null` disables XMPP ping support.

Test
----
Expand Down
4 changes: 3 additions & 1 deletion emulsion.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"room": "[email protected]",
"roomPassword": "// optional",
"nickname": "хортолёт",
"messageTimeout": "00:05:00"
"messageTimeout": "00:05:00",
"pingInterval": "00:01:00",
"pingTimeout": "00:00:05"
},
"telegram": {
"token": "999999999:aaaaaaaaaaaaaaaaaaaaaaaaa_777777777",
Expand Down

0 comments on commit 41b656c

Please sign in to comment.