diff --git a/html/main.html b/html/main.html index 2f21aee3..1f9e0e72 100644 --- a/html/main.html +++ b/html/main.html @@ -38,7 +38,7 @@
- +
{{id}}
<%template "extra-body" .%> diff --git a/server.conf.in b/server.conf.in index 418da8c1..93645779 100644 --- a/server.conf.in +++ b/server.conf.in @@ -16,6 +16,7 @@ sessionSecret = the-default-secret-do-not-keep #tokenFile = tokens.txt # If set, everyone needs to give one of the tokens to launch the web client. One token per line in the file. #globalRoom = global # Enables a global room. Users in that room are in all rooms. #extra = /usr/share/spreed-speakfreely-server/extra # Extra templates directory. Add .html files to define extra-* template slots here. +#plugin = plugins/example1 # Plugin support. [log] #logfile = /var/log/spreed-speakfreely-server.log diff --git a/src/app/spreed-speakfreely-server/config.go b/src/app/spreed-speakfreely-server/config.go index fc0c1c20..470d1931 100644 --- a/src/app/spreed-speakfreely-server/config.go +++ b/src/app/spreed-speakfreely-server/config.go @@ -33,9 +33,10 @@ type Config struct { Tokens bool // True when we got a tokens file Version string // Server version number globalRoomid string // Id of the global room (not exported to Javascript) + Plugin string // Plugin to load } -func NewConfig(title, ver, runtimeVersion string, stunURIs, turnURIs []string, tokens bool, globalRoomid string) *Config { +func NewConfig(title, ver, runtimeVersion string, stunURIs, turnURIs []string, tokens bool, globalRoomid, plugin string) *Config { sv := fmt.Sprintf("static/ver=%s", ver) - return &Config{Title: title, ver: ver, S: sv, StunURIs: stunURIs, TurnURIs: turnURIs, Tokens: tokens, Version: runtimeVersion, globalRoomid: globalRoomid} + return &Config{Title: title, ver: ver, S: sv, StunURIs: stunURIs, TurnURIs: turnURIs, Tokens: tokens, Version: runtimeVersion, globalRoomid: globalRoomid, Plugin: plugin} } diff --git a/src/app/spreed-speakfreely-server/main.go b/src/app/spreed-speakfreely-server/main.go index 1373f1e9..470b44c5 100644 --- a/src/app/spreed-speakfreely-server/main.go +++ b/src/app/spreed-speakfreely-server/main.go @@ -205,6 +205,11 @@ func runner(runtime phoenix.Runtime) error { globalRoomid = "" } + plugin, err := runtime.GetString("app", "plugin") + if err != nil { + plugin = "" + } + // Create token provider. var tokenProvider TokenProvider if tokenFile != "" { @@ -213,7 +218,7 @@ func runner(runtime phoenix.Runtime) error { } // Create configuration data structure. - config = NewConfig(title, ver, runtimeVersion, stunURIs, turnURIs, tokenProvider != nil, globalRoomid) + config = NewConfig(title, ver, runtimeVersion, stunURIs, turnURIs, tokenProvider != nil, globalRoomid, plugin) // Load templates. tt := template.New("") diff --git a/static/js/app.js b/static/js/app.js index 27d59fed..183f5e24 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -143,6 +143,8 @@ define([ }); + return app; + }; return { diff --git a/static/js/main.js b/static/js/main.js index faf54cb1..477884d9 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -140,10 +140,22 @@ define([ 'base' ], function ($, _, angular, require) { - require(['app'], function(App) { - - App.initialize(); - + // Dynamic app loader with plugin support. + var load = ['app']; + _.each(document.getElementsByTagName('script'), function(script) { + var dataPlugin = script.getAttribute('data-plugin'); + if (dataPlugin) { + load.push(dataPlugin); + } + }); + require(load, function(App) { + var app = App.initialize(); + var args = Array.prototype.slice.call(arguments, 1); + _.each(args, function(plugin) { + if (plugin && plugin.initialize) { + plugin.initialize(app) + } + }) }); }); diff --git a/static/js/plugins/example1.js b/static/js/plugins/example1.js new file mode 100644 index 00000000..de993d14 --- /dev/null +++ b/static/js/plugins/example1.js @@ -0,0 +1,8 @@ +// Example plugin shows the basic API. +define([], function() { + return { + initialize: function(app) { + console.log("Example plugin 1 loaded.", app); + } + } +});