git ssb

2+

cel / ssb-party



Tree: 8b6827337d6c9a677261c5987cb95bbee685d870

Files: 8b6827337d6c9a677261c5987cb95bbee685d870 / autoclose.js

632 bytesRaw
1exports.name = 'autoclose'
2exports.version = '0.0.0'
3exports.init = function (sbot, config) {
4
5 // shut down when no connections for a while
6 var timer
7 var keepalive = config.timers && config.timers.keepalive || 30e3
8 var connections = 0
9 sbot.on('rpc:connect', function (rpc) {
10 clearTimeout(timer)
11 connections++
12 rpc.on('closed', function () {
13 if (!--connections) timer = setTimeout(autoclose, keepalive)
14 })
15 })
16
17 function autoclose() {
18 // this is grepped for in tests
19 console.log('sbot auto closing')
20 sbot.close(function (err) {
21 if (err) throw err
22 process.exit(0)
23 })
24 }
25}
26

Built with git-ssb-web