From efd68e725cc48727b2b94a3f6705bc91c6a62a7a Mon Sep 17 00:00:00 2001 From: Claudio Costa Date: Mon, 28 Feb 2022 14:01:16 +0100 Subject: [PATCH 1/2] Fix logging --- webapp/src/client.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/webapp/src/client.ts b/webapp/src/client.ts index 8f363ad2a..f6367999a 100644 --- a/webapp/src/client.ts +++ b/webapp/src/client.ts @@ -112,8 +112,7 @@ export default class CallsClient extends EventEmitter { this.ws = ws; ws.on('error', (err) => { - console.log(`ws error: ${err}`); - this.ws = null; + console.log('ws error', err); this.disconnect(); }); @@ -168,7 +167,7 @@ export default class CallsClient extends EventEmitter { } }); peer.on('error', (err) => { - console.log(`peer error: ${err}`); + console.log('peer error', err); this.disconnect(); }); peer.on('stream', (remoteStream) => { From 5c5e9523785bde747b4f310044716d420a3b072c Mon Sep 17 00:00:00 2001 From: Claudio Costa Date: Mon, 28 Feb 2022 14:23:14 +0100 Subject: [PATCH 2/2] Implement opt out option for channel calls --- plugin.json | 12 ++++++++++-- server/api.go | 8 ++++++++ server/configuration.go | 15 +++++++++++++-- server/configuration_test.go | 3 +++ server/manifest.go | 10 +++++++++- server/session.go | 16 +++++++++++++++- 6 files changed, 58 insertions(+), 6 deletions(-) diff --git a/plugin.json b/plugin.json index 18591fcbc..2c5665682 100644 --- a/plugin.json +++ b/plugin.json @@ -45,8 +45,16 @@ "key": "AllowEnableCalls", "display_name": "Allow Enable Calls", "type": "bool", - "help_text": "When set to true, it allows channel admins to enable calls in their channels. It also allows participants of DMs/GMs to enable calls.", + "help_text": "When set to true, it allows channel admins to enable or disable calls in their channels. It also allows participants of DMs/GMs to enable or disable calls.", "default": false - }] + }, + { + "key": "DefaultEnabled", + "display_name": "Default Enabled Calls", + "type": "bool", + "help_text": "When set to true, calls will be possible in all channels where they are not explicitly disabled.", + "default": true + } + ] } } diff --git a/server/api.go b/server/api.go index 59f88f8d4..8e5cf4532 100644 --- a/server/api.go +++ b/server/api.go @@ -57,6 +57,14 @@ func (p *Plugin) handleGetChannel(w http.ResponseWriter, r *http.Request, channe info := ChannelState{ ChannelID: channelID, } + + cfg := p.getConfiguration() + if state == nil && cfg.DefaultEnabled != nil && *cfg.DefaultEnabled { + state = &channelState{ + Enabled: true, + } + } + if state != nil { info.Enabled = state.Enabled if state.Call != nil { diff --git a/server/configuration.go b/server/configuration.go index 37a03a02b..77f30ba59 100644 --- a/server/configuration.go +++ b/server/configuration.go @@ -32,9 +32,11 @@ type configuration struct { type clientConfig struct { // A comma separated list of ICE servers URLs (STUN/TURN) to use. ICEServers ICEServers - // When set to true, it allows channel admins to enable calls in their channels. - // It also allows participants of DMs/GMs to enable calls. + // When set to true, it allows channel admins to enable or disable calls in their channels. + // It also allows participants of DMs/GMs to enable or disable calls. AllowEnableCalls *bool + // When set to true, calls will be possible in all channels where they are not explicitly disabled. + DefaultEnabled *bool } type ICEServers []string @@ -96,6 +98,7 @@ func (pr PortsRange) IsValid() error { func (c *configuration) getClientConfig() clientConfig { return clientConfig{ AllowEnableCalls: c.AllowEnableCalls, + DefaultEnabled: c.DefaultEnabled, ICEServers: c.ICEServers, } } @@ -107,6 +110,10 @@ func (c *configuration) SetDefaults() { if c.AllowEnableCalls == nil { c.AllowEnableCalls = new(bool) } + if c.DefaultEnabled == nil { + c.DefaultEnabled = new(bool) + *c.DefaultEnabled = true + } } func (c *configuration) IsValid() error { @@ -140,6 +147,10 @@ func (c *configuration) Clone() *configuration { cfg.AllowEnableCalls = model.NewBool(*c.AllowEnableCalls) } + if c.DefaultEnabled != nil { + cfg.DefaultEnabled = model.NewBool(*c.DefaultEnabled) + } + if c.ICEServers != nil { cfg.ICEServers = make(ICEServers, len(c.ICEServers)) for i, u := range c.ICEServers { diff --git a/server/configuration_test.go b/server/configuration_test.go index b6724b1c8..ec440a906 100644 --- a/server/configuration_test.go +++ b/server/configuration_test.go @@ -75,7 +75,10 @@ func TestGetClientConfig(t *testing.T) { cfg.SetDefaults() clientCfg := cfg.getClientConfig() require.Equal(t, cfg.AllowEnableCalls, clientCfg.AllowEnableCalls) + require.Equal(t, cfg.DefaultEnabled, clientCfg.DefaultEnabled) *cfg.AllowEnableCalls = true + *cfg.DefaultEnabled = true clientCfg = cfg.getClientConfig() require.Equal(t, cfg.AllowEnableCalls, clientCfg.AllowEnableCalls) + require.Equal(t, cfg.DefaultEnabled, clientCfg.DefaultEnabled) } diff --git a/server/manifest.go b/server/manifest.go index d8951b50c..e255a3ba4 100644 --- a/server/manifest.go +++ b/server/manifest.go @@ -62,9 +62,17 @@ const manifestStr = ` "key": "AllowEnableCalls", "display_name": "Allow Enable Calls", "type": "bool", - "help_text": "When set to true, it allows channel admins to enable calls in their channels. It also allows participants of DMs/GMs to enable calls.", + "help_text": "When set to true, it allows channel admins to enable or disable calls in their channels. It also allows participants of DMs/GMs to enable or disable calls.", "placeholder": "", "default": false + }, + { + "key": "DefaultEnabled", + "display_name": "Default Enabled Calls", + "type": "bool", + "help_text": "When set to true, calls will be possible in all channels where they are not explicitly disabled.", + "placeholder": "", + "default": true } ] } diff --git a/server/session.go b/server/session.go index 410d5dcd3..d63d41754 100644 --- a/server/session.go +++ b/server/session.go @@ -64,10 +64,24 @@ func newUserSession(userID, channelID, connID string) *session { func (p *Plugin) addUserSession(userID, channelID string, userSession *session) (channelState, error) { var st channelState + + cfg := p.getConfiguration() + err := p.kvSetAtomicChannelState(channelID, func(state *channelState) (*channelState, error) { if state == nil { - return nil, fmt.Errorf("channel state is missing from store") + if cfg.DefaultEnabled != nil && *cfg.DefaultEnabled { + state = &channelState{ + Enabled: true, + } + } else { + return nil, fmt.Errorf("channel state is missing from store") + } } + + if !state.Enabled { + return nil, fmt.Errorf("calls are not enabled") + } + if state.Call == nil { state.Call = &callState{ ID: model.NewId(),