| 1 | return function (opts, arg) |
| 2 | if opts.short_help then |
| 3 | print("Measure the round-trip latency time of a given JID"); |
| 4 | return; |
| 5 | end |
| 6 | if #arg == 0 or opts.help then |
| 7 | return 0; |
| 8 | end |
| 9 | local conn; |
| 10 | local function on_reply(time, jid, reply) |
| 11 | if time then |
| 12 | print(string.format("%s latency: %1.3fs", jid, time)); |
| 13 | else |
| 14 | print("Error requesting ping ("..(reply.condition or "unknown")..")"..(reply.text and (": "..reply.text) or "")); |
| 15 | end |
| 16 | conn:close(); |
| 17 | end |
| 18 | local function on_connect(_conn) |
| 19 | conn = _conn; |
| 20 | conn:add_plugin("ping"); |
| 21 | conn:ping(arg[1], on_reply); |
| 22 | end |
| 23 | clix_connect(opts, on_connect); |
| 24 | end |