Browse Source

Allow slashes unquoted in room names. This brings nested rooms.

pull/194/head
Simon Eisenmann 11 years ago
parent
commit
e0fa8c8b43
  1. 6
      src/app/spreed-webrtc-server/main.go
  2. 2
      static/js/app.js
  3. 45
      static/js/services/resturl.js
  4. 11
      static/js/services/rooms.js

6
src/app/spreed-webrtc-server/main.go

@ -352,6 +352,8 @@ func runner(runtime phoenix.Runtime) error {
r.Handle("/robots.txt", http.StripPrefix(config.B, http.FileServer(http.Dir(path.Join(rootFolder, "static"))))) r.Handle("/robots.txt", http.StripPrefix(config.B, http.FileServer(http.Dir(path.Join(rootFolder, "static")))))
r.Handle("/favicon.ico", http.StripPrefix(config.B, http.FileServer(http.Dir(path.Join(rootFolder, "static", "img"))))) r.Handle("/favicon.ico", http.StripPrefix(config.B, http.FileServer(http.Dir(path.Join(rootFolder, "static", "img")))))
r.Handle("/ws", makeWSHandler(statsManager, sessionManager, codec, channellingAPI)) r.Handle("/ws", makeWSHandler(statsManager, sessionManager, codec, channellingAPI))
// Simple room handler.
r.HandleFunc("/{room}", httputils.MakeGzipHandler(roomHandler)) r.HandleFunc("/{room}", httputils.MakeGzipHandler(roomHandler))
// Add API end points. // Add API end points.
@ -382,6 +384,10 @@ func runner(runtime phoenix.Runtime) error {
} }
} }
// Map everything else to a room when it is a GET.
rooms := r.PathPrefix("/").Methods("GET").Subrouter()
rooms.HandleFunc("/{room:.*}", httputils.MakeGzipHandler(roomHandler))
return runtime.Start() return runtime.Start()
} }

2
static/js/app.js

@ -154,7 +154,7 @@ define([
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|file|filesystem|blob):/); $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|file|filesystem|blob):/);
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|filesystem|blob):|data:image\//); $compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|filesystem|blob):|data:image\//);
// Setup routing // Setup routing
$routeProvider.when("/:room", {}); $routeProvider.when("/:room*", {});
// Use HTML5 routing. // Use HTML5 routing.
$locationProvider.html5Mode(true); $locationProvider.html5Mode(true);
}]); }]);

45
static/js/services/resturl.js

@ -20,21 +20,42 @@
*/ */
"use strict"; "use strict";
define([ define(["underscore"], function(_) {
], function() {
// restURL
return ["globalContext", "$window", function(context, $window) { return ["globalContext", "$window", function(context, $window) {
return { var RestURL = function() {};
room: function(id) { RestURL.prototype.room = function(name) {
id = $window.encodeURIComponent(id); var url = this.encodeRoomURL(name);
return $window.location.protocol + '//' + $window.location.host + context.Cfg.B + id; return $window.location.protocol + '//' + $window.location.host + context.Cfg.B + url;
}, };
buddy: function(id) { RestURL.prototype.buddy = function(id) {
return $window.location.protocol + '//' + $window.location.host + context.Cfg.B + "static/img/buddy/s46/" + id; return $window.location.protocol + '//' + $window.location.host + context.Cfg.B + "static/img/buddy/s46/" + id;
}, };
api: function(path) { RestURL.prototype.api = function(path) {
return (context.Cfg.B || "/") + "api/v1/" + path; return (context.Cfg.B || "/") + "api/v1/" + path;
};
RestURL.prototype.encodeRoomURL = function(name, prefix) {
// Split parts so slashes are allowed.
var parts = name.split("/");
var url = [];
if (typeof prefix !== "undefined") {
url.push(prefix);
}
// Allow some thing in room name parts.
_.each(parts, function(p) {
p = $window.encodeURIComponent(p);
p = p.replace(/^%40/, "@");
p = p.replace(/^%24/, "$");
p = p.replace(/^%2B/, "+");
url.push(p);
});
if (url.length > 1 && url[url.length-1] === "") {
// Remove trailing slash if any.
url.pop();
} }
return url.join("/");
}; };
return new RestURL();
}]; }];
}); });

11
static/js/services/rooms.js

@ -103,7 +103,7 @@ define([
currentRoom = room; currentRoom = room;
if (priorRoom) { if (priorRoom) {
priorRoomName = priorRoom.Name; priorRoomName = priorRoom.Name;
console.log("Left room", priorRoom.Name); console.log("Left room", [priorRoom.Name]);
$rootScope.$broadcast("room.left", priorRoom.Name); $rootScope.$broadcast("room.left", priorRoom.Name);
} }
if (currentRoom) { if (currentRoom) {
@ -212,13 +212,10 @@ define([
return canJoinRooms; return canJoinRooms;
}, },
joinByName: function(name, replace) { joinByName: function(name, replace) {
name = $window.encodeURIComponent(name); var url = restURL.encodeRoomURL(name, "");
name = name.replace(/^%40/, "@"); // Apply new URL.
name = name.replace(/^%24/, "$");
name = name.replace(/^%2B/, "+");
safeApply($rootScope, function(scope) { safeApply($rootScope, function(scope) {
$location.path("/" + name); $location.path(url);
if (replace) { if (replace) {
$location.replace(); $location.replace();
} }

Loading…
Cancel
Save