Skip to content

Commit c2dc5df

Browse files
committed
Merge pull request #174 from longsleep/contacts-module-disable
Contacts can now be disabled on server module level (server.conf).
2 parents d36f19f + 0e2f660 commit c2dc5df

File tree

13 files changed

+169
-44
lines changed

13 files changed

+169
-44
lines changed

server.conf.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ serverRealm = local
124124
;screensharing = true
125125
;youtube = true
126126
;presentation = true
127+
;contacts = true
127128

128129
[log]
129130
;logfile = /var/log/spreed-webrtc-server.log

src/app/spreed-webrtc-server/channelling_api.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ func (api *channellingAPI) OnIncoming(c ResponseSender, session *Session, msg *D
139139
}
140140
} else {
141141
if msg.Chat.Chat.Status != nil && msg.Chat.Chat.Status.ContactRequest != nil {
142+
if !api.Config.WithModule("contacts") {
143+
return
144+
}
142145
if err := api.contactrequestHandler(session, msg.Chat.To, msg.Chat.Chat.Status.ContactRequest); err != nil {
143146
log.Println("Ignoring invalid contact request.", err)
144147
return
@@ -173,10 +176,14 @@ func (api *channellingAPI) OnIncoming(c ResponseSender, session *Session, msg *D
173176
var users []*DataSession
174177
switch msg.Sessions.Sessions.Type {
175178
case "contact":
176-
if userID, err := api.getContactID(session, msg.Sessions.Sessions.Token); err == nil {
177-
users = api.GetUserSessions(session, userID)
179+
if api.Config.WithModule("contacts") {
180+
if userID, err := api.getContactID(session, msg.Sessions.Sessions.Token); err == nil {
181+
users = api.GetUserSessions(session, userID)
182+
} else {
183+
log.Printf(err.Error())
184+
}
178185
} else {
179-
log.Printf(err.Error())
186+
log.Printf("Incoming contacts session request with contacts disabled")
180187
}
181188
case "session":
182189
id, err := session.attestation.Decode(msg.Sessions.Sessions.Token)

src/app/spreed-webrtc-server/config.go

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,27 @@ import (
3131
)
3232

3333
type Config struct {
34-
Title string // Title
35-
ver string // Version (not exported to Javascript)
36-
S string // Static URL prefix with version
37-
B string // Base URL
38-
Token string // Server token
39-
StunURIs []string // STUN server URIs
40-
TurnURIs []string // TURN server URIs
41-
Tokens bool // True when we got a tokens file
42-
Version string // Server version number
43-
UsersEnabled bool // Flag if users are enabled
44-
UsersAllowRegistration bool // Flag if users can register
45-
UsersMode string // Users mode string
46-
DefaultRoomEnabled bool // Flag if default room ("") is enabled
47-
Plugin string // Plugin to load
48-
AuthorizeRoomCreation bool // Whether a user account is required to create rooms
49-
AuthorizeRoomJoin bool // Whether a user account is required to join rooms
50-
Modules []string // List of enabled modules
51-
globalRoomID string // Id of the global room (not exported to Javascript)
52-
contentSecurityPolicy string // HTML content security policy
53-
contentSecurityPolicyReportOnly string // HTML content security policy in report only mode
34+
Title string // Title
35+
ver string // Version (not exported to Javascript)
36+
S string // Static URL prefix with version
37+
B string // Base URL
38+
Token string // Server token
39+
StunURIs []string // STUN server URIs
40+
TurnURIs []string // TURN server URIs
41+
Tokens bool // True when we got a tokens file
42+
Version string // Server version number
43+
UsersEnabled bool // Flag if users are enabled
44+
UsersAllowRegistration bool // Flag if users can register
45+
UsersMode string // Users mode string
46+
DefaultRoomEnabled bool // Flag if default room ("") is enabled
47+
Plugin string // Plugin to load
48+
AuthorizeRoomCreation bool // Whether a user account is required to create rooms
49+
AuthorizeRoomJoin bool // Whether a user account is required to join rooms
50+
Modules []string // List of enabled modules
51+
modulesTable map[string]bool // Map of enabled modules
52+
globalRoomID string // Id of the global room (not exported to Javascript)
53+
contentSecurityPolicy string // HTML content security policy
54+
contentSecurityPolicyReportOnly string // HTML content security policy in report only mode
5455
}
5556

5657
func NewConfig(container phoenix.Container, tokens bool) *Config {
@@ -88,11 +89,18 @@ func NewConfig(container phoenix.Container, tokens bool) *Config {
8889
trimAndRemoveDuplicates(&turnURIs)
8990

9091
// Get enabled modules.
91-
allModules := []string{"screensharing", "youtube", "presentation"}
92-
modules := allModules[:0]
93-
for _, module := range allModules {
92+
modulesTable := map[string]bool{
93+
"screensharing": true,
94+
"youtube": true,
95+
"presentation": true,
96+
"contacts": true,
97+
}
98+
modules := []string{}
99+
for module, _ := range modulesTable {
94100
if container.GetBoolDefault("modules", module, true) {
95101
modules = append(modules, module)
102+
} else {
103+
modulesTable[module] = false
96104
}
97105
}
98106
log.Println("Enabled modules:", modules)
@@ -115,6 +123,7 @@ func NewConfig(container phoenix.Container, tokens bool) *Config {
115123
AuthorizeRoomCreation: container.GetBoolDefault("app", "authorizeRoomCreation", false),
116124
AuthorizeRoomJoin: container.GetBoolDefault("app", "authorizeRoomJoin", false),
117125
Modules: modules,
126+
modulesTable: modulesTable,
118127
globalRoomID: container.GetStringDefault("app", "globalRoom", ""),
119128
contentSecurityPolicy: container.GetStringDefault("app", "contentSecurityPolicy", ""),
120129
contentSecurityPolicyReportOnly: container.GetStringDefault("app", "contentSecurityPolicyReportOnly", ""),
@@ -125,6 +134,15 @@ func (config *Config) Get(request *http.Request) (int, interface{}, http.Header)
125134
return 200, config, http.Header{"Content-Type": {"application/json; charset=utf-8"}}
126135
}
127136

137+
func (config *Config) WithModule(m string) bool {
138+
139+
if val, ok := config.modulesTable[m]; ok && val {
140+
return true
141+
}
142+
return false
143+
144+
}
145+
128146
// Helper function to clean up string arrays.
129147
func trimAndRemoveDuplicates(data *[]string) {
130148
found := make(map[string]bool)

src/styles/global/_withs.scss

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Spreed WebRTC.
3+
* Copyright (C) 2013-2014 struktur AG
4+
*
5+
* This file is part of Spreed WebRTC.
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
.visible-with-contacts,
23+
.visible-with-contacts-inline {
24+
display: none;
25+
}
26+
27+
.hidden-with-contacts {
28+
}
29+
30+
.with-contacts {
31+
32+
.visible-with-contacts {
33+
display: block;
34+
}
35+
36+
.visible-with-contacts-inline {
37+
display: inline-block;
38+
}
39+
40+
.hidden-with-contacts {
41+
display: none;
42+
}
43+
44+
}

src/styles/main.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
@import "global/nicescroll";
3434
@import "global/animations";
3535
@import "global/overlaybar";
36+
@import "global/withs";
3637

3738
@import "components/rightslide";
3839
@import "components/bar";

static/css/main.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/js/directives/buddylist.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) {
141141
}
142142
scope.$apply();
143143
});
144+
if (contacts.enabled) {
145+
iElement.addClass("with-contacts");
146+
}
144147

145148
};
146149

static/js/directives/menu.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,10 @@
2323
define(['text!partials/menu.html'], function(template) {
2424

2525
// menu
26-
return ["mediaStream", function(mediaStream) {
26+
return ["modules", function(modules) {
2727

2828
var link = function($scope, $element) {
29-
30-
$scope.modules = mediaStream.config.Modules || [];
31-
$scope.withModule = function(m) {
32-
return $scope.modules.indexOf(m) !== -1;
33-
};
34-
29+
$scope.withModule = modules.withModule;
3530
};
3631

3732
return {

static/js/services/contacts.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,23 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana
123123
};
124124

125125
// contacts
126-
return ["appData", "contactData", "mediaStream", "$templateCache", function(appData, contactData, mediaStream, $templateCache) {
126+
return ["appData", "contactData", "mediaStream", "$templateCache", "modules", function(appData, contactData, mediaStream, $templateCache, modules) {
127127

128-
// Inject our templates.
129-
$templateCache.put('/contactsmanager/main.html', templateContactsManager);
130-
$templateCache.put('/contactsmanager/edit.html', templateContactsManagerEdit);
128+
var withContacts = modules.withModule("contacts");
129+
130+
if (withContacts) {
131+
// Inject our templates.
132+
$templateCache.put('/contactsmanager/main.html', templateContactsManager);
133+
$templateCache.put('/contactsmanager/edit.html', templateContactsManagerEdit);
134+
}
131135

132136
var Contacts = function() {
133137

134138
this.e = $({});
135139
this.userid = null;
136140
this.key = null;
137141
this.database = null;
142+
this.enabled = withContacts;
138143

139144
appData.e.on("authenticationChanged", _.bind(function(event, userid, suserid) {
140145
// TODO(longsleep): Avoid creating empty databases. Create db on store only.
@@ -160,14 +165,24 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana
160165
};
161166

162167
Contacts.prototype.put = function(contact) {
168+
169+
if (!this.database) {
170+
console.warn("Unable to put contact as no database is loaded.");
171+
return;
172+
}
163173
this.database.put("contacts", {
164174
id: this.id(contact.Userid),
165175
contact: this.encrypt(contact)
166176
});
167-
}
177+
178+
};
168179

169180
Contacts.prototype.open = function(userid, suserid) {
170181

182+
if (!this.enabled) {
183+
return null;
184+
}
185+
171186
if (this.database && (!userid || this.userid !== userid)) {
172187
// Unload existing contacts.
173188
this.unload();

static/js/services/modules.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Spreed WebRTC.
3+
* Copyright (C) 2013-2014 struktur AG
4+
*
5+
* This file is part of Spreed WebRTC.
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
"use strict";
23+
define([], function() {
24+
25+
// modules
26+
return ["mediaStream", function(mediaStream) {
27+
28+
var enabledModules = mediaStream.config.Modules || [];
29+
30+
// Public api.
31+
return {
32+
withModule: function(m) {
33+
return enabledModules.indexOf(m) !== -1;
34+
}
35+
}
36+
37+
}];
38+
});

0 commit comments

Comments
 (0)