Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Issue #180

  • Loading branch information...
commit 481b88b4e5c1e7f94d5d67215f0f9b245c81fd87 1 parent 86c4518
@bpburns bpburns authored
View
14 servers/java/coweb-javascript/src/main/webapp/coweb/session/BayeuxSession.js
@@ -31,9 +31,19 @@ define([
this._loginUrl = null;
this._logoutUrl = null;
this._cacheState = false;
+
+ this._navigateListeners = [];
};
var proto = BayeuxSession.prototype;
+ proto.addNavigateListener = function(listener) {
+ this._bridge.addNavigateListener(listener);
+ };
+
+ proto.removeNavigateListener = function(listener) {
+ this._bridge.removeNavigateListener(listener);
+ };
+
/**
* Stores coweb configuration info and the ListenerInterface impl to use.
*
@@ -275,6 +285,10 @@ define([
return this._prepParams.promise;
};
+ proto.navigate = function(url) {
+ this._bridge.navigate(url);
+ };
+
proto._cowebkeyFromHash = function() {
var hash = window.location.hash;
if(!hash || hash.indexOf('cowebkey') == -1) {
View
22 servers/java/coweb-javascript/src/main/webapp/coweb/session/bayeux/ListenerBridge.js
@@ -11,8 +11,9 @@
define([
'coweb/session/bayeux/cometd',
'coweb/util/Promise',
- 'coweb/util/lang'
-], function(cometd, Promise, lang) {
+ 'coweb/util/lang',
+ 'coweb/topics'
+], function(cometd, Promise, lang, topics) {
/**
* @constructor
* @param {Object} args.listener ListenerInterface instance
@@ -36,6 +37,8 @@ define([
this._updaterToken = null;
// /session/sync/* subscription
this._syncToken = null;
+ // /session/admin/ subscription
+ this._adminToken = null;
// active requests for state
this._stateReqs = {};
// state of the join process
@@ -218,6 +221,7 @@ define([
*/
proto.initiateUpdate = function() {
//the session id to the channel names.
+ this.adminChannel = '/session/'+this._bridge.prepResponse.sessionid+'/admin';
this.syncChannel = '/session/'+this._bridge.prepResponse.sessionid+'/sync/*';
this.syncAppChannel = '/session/'+this._bridge.prepResponse.sessionid+'/sync/app';
this.syncEngineChannel = '/session/'+this._bridge.prepResponse.sessionid+'/sync/engine';
@@ -245,6 +249,8 @@ define([
//this._syncToken = cometd.subscribe('/service/session/sync/*',
this._syncToken = cometd.subscribe(this.syncChannel,
this, '_onSessionSync');
+ this._adminToken = cometd.subscribe(this.adminChannel,
+ this, '_onSessionAdmin');
// start the joining process
this._joinToken = cometd.subscribe('/service/session/join/*',
this, '_onServiceSessionJoin');
@@ -468,6 +474,18 @@ define([
console.warn('bayeux.ListenerBridge: received unknown sync ' + ch);
}
};
+
+ proto._onSessionAdmin = function(msg) {
+ if(!msg.data.value.url) {
+ return;
+ }
+
+ this._bridge.fireNavigationEvent(msg.data.value.url);
+
+ setTimeout(function() {
+ window.location = msg.data.value.url;
+ }, 2000);
+ };
/**
* Called to handle a /session/roster/ message. Forwards it to the
View
41 servers/java/coweb-javascript/src/main/webapp/coweb/session/bayeux/SessionBridge.js
@@ -14,8 +14,9 @@ define([
'coweb/session/bayeux/ListenerBridge',
'coweb/util/Promise',
'coweb/util/xhr',
- 'org/requirejs/i18n!../../nls/messages'
-], function(cometd, CowebExtension, ListenerBridge, Promise, xhr, messages) {
+ 'org/requirejs/i18n!../../nls/messages',
+ 'coweb/topics'
+], function(cometd, CowebExtension, ListenerBridge, Promise, xhr, messages, topics) {
/**
* @constructor
* @param {Boolean} args.debug True if in debug more, false if not
@@ -51,6 +52,8 @@ define([
// info received from server
this.prepResponse = null;
+ this._navigateListeners = [];
+
// build listener bridge instance
this._bridge = new ListenerBridge({
debug: this._debug,
@@ -61,6 +64,31 @@ define([
// save typing and lookup
var proto = SessionBridge.prototype;
+ proto.addNavigateListener = function(listener) {
+
+ for(var i=0; i<this._navigateListeners; i++) {
+ if(this._navigateListeners[i] === listener) {
+ return;
+ }
+ }
+
+ this._navigateListeners.push(listener);
+ };
+
+ proto.fireNavigationEvent = function(obj) {
+ for(var i=0; i<this._navigateListeners.length; i++) {
+ this._navigateListeners[i].call(obj);
+ }
+ };
+
+ proto.removeNavigateListener = function(listener) {
+ for(var i=0; i<this._navigateListeners; i++) {
+ if(this._navigateListeners[i] === listener) {
+ this._navigateListeners.splice(i, 1);
+ break;
+ }
+ }
+ };
/**
* Destroys the instance. Voids all promises without resolution. Attempts
* a disconnect from the server if not idle.
@@ -186,6 +214,15 @@ define([
return this._joinPromise;
};
+ proto.navigate = function(url) {
+ cometd.publish(this._bridge.adminChannel, {
+ value: {
+ url: url
+ },
+ topic: topics.ADMIN
+ });
+ };
+
/**
* Called on /meta/unsuccessful notification from the cometd client for
* any error. Forces a disconnect to prevent attempts to reconnect with
View
4 servers/java/coweb-javascript/src/main/webapp/coweb/topics.js
@@ -35,7 +35,9 @@ define(function() {
BUSY : p+'busy.change',
// pausing and resuming topics
PAUSE_TOPIC : p+'topics.pause',
- RESUME_TOPIC : p+'topics.resume'
+ RESUME_TOPIC : p+'topics.resume',
+
+ ADMIN : p +'admin.navigate'
};
});
Please sign in to comment.
Something went wrong with that request. Please try again.