Browse Source

Added html frontend plugin support.

pull/1/head
Simon Eisenmann 12 years ago
parent
commit
31dbb411ca
  1. 2
      html/main.html
  2. 1
      server.conf.in
  3. 5
      src/app/spreed-speakfreely-server/config.go
  4. 7
      src/app/spreed-speakfreely-server/main.go
  5. 2
      static/js/app.js
  6. 20
      static/js/main.js
  7. 8
      static/js/plugins/example1.js

2
html/main.html

@ -38,7 +38,7 @@
<div class="ng-cloak" id="buddylist"><buddy-list/></div> <div class="ng-cloak" id="buddylist"><buddy-list/></div>
<div class="ng-cloak" id="settings" ng-class="{show: showSettings}"><settings/></div> <div class="ng-cloak" id="settings" ng-class="{show: showSettings}"><settings/></div>
<div class="ng-cloak" id="chat"><chat/></div> <div class="ng-cloak" id="chat"><chat/></div>
<script data-main="<%.Cfg.S%>/js/<%.App%>" src="<%.Cfg.S%>/js/libs/require/require.js"></script> <script data-main="<%.Cfg.S%>/js/<%.App%>" data-plugin="<%.Cfg.Plugin%>" src="<%.Cfg.S%>/js/libs/require/require.js"></script>
<div class="ng-cloak" id="details">{{id}}</div> <div class="ng-cloak" id="details">{{id}}</div>
<%template "extra-body" .%> <%template "extra-body" .%>
</body> </body>

1
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. #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. #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. #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] [log]
#logfile = /var/log/spreed-speakfreely-server.log #logfile = /var/log/spreed-speakfreely-server.log

5
src/app/spreed-speakfreely-server/config.go

@ -33,9 +33,10 @@ type Config struct {
Tokens bool // True when we got a tokens file Tokens bool // True when we got a tokens file
Version string // Server version number Version string // Server version number
globalRoomid string // Id of the global room (not exported to Javascript) 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) 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}
} }

7
src/app/spreed-speakfreely-server/main.go

@ -205,6 +205,11 @@ func runner(runtime phoenix.Runtime) error {
globalRoomid = "" globalRoomid = ""
} }
plugin, err := runtime.GetString("app", "plugin")
if err != nil {
plugin = ""
}
// Create token provider. // Create token provider.
var tokenProvider TokenProvider var tokenProvider TokenProvider
if tokenFile != "" { if tokenFile != "" {
@ -213,7 +218,7 @@ func runner(runtime phoenix.Runtime) error {
} }
// Create configuration data structure. // 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. // Load templates.
tt := template.New("") tt := template.New("")

2
static/js/app.js

@ -143,6 +143,8 @@ define([
}); });
return app;
}; };
return { return {

20
static/js/main.js

@ -140,10 +140,22 @@ define([
'base' 'base'
], function ($, _, angular, require) { ], function ($, _, angular, require) {
require(['app'], function(App) { // Dynamic app loader with plugin support.
var load = ['app'];
App.initialize(); _.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)
}
})
}); });
}); });

8
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);
}
}
});
Loading…
Cancel
Save