Skip to content
This repository
Browse code

Issue #180

  • Loading branch information...
commit 481b88b4e5c1e7f94d5d67215f0f9b245c81fd87 1 parent 86c4518
Brian Burns authored June 13, 2012
14  servers/java/coweb-javascript/src/main/webapp/coweb/session/BayeuxSession.js
@@ -31,9 +31,19 @@ define([
31 31
         this._loginUrl = null;
32 32
         this._logoutUrl = null;
33 33
         this._cacheState = false;
  34
+
  35
+		this._navigateListeners = [];
34 36
     };
35 37
     var proto = BayeuxSession.prototype;
36 38
 
  39
+	proto.addNavigateListener = function(listener) {
  40
+		this._bridge.addNavigateListener(listener);
  41
+	};
  42
+	
  43
+	proto.removeNavigateListener = function(listener) {
  44
+		this._bridge.removeNavigateListener(listener);
  45
+	};
  46
+
37 47
     /**
38 48
      * Stores coweb configuration info and the ListenerInterface impl to use.
39 49
      *
@@ -275,6 +285,10 @@ define([
275 285
         return this._prepParams.promise;
276 286
     };
277 287
 
  288
+	proto.navigate = function(url) {
  289
+		this._bridge.navigate(url);
  290
+	};
  291
+
278 292
 	proto._cowebkeyFromHash = function() {
279 293
 		var hash = window.location.hash;
280 294
 		if(!hash || hash.indexOf('cowebkey') == -1) {
22  servers/java/coweb-javascript/src/main/webapp/coweb/session/bayeux/ListenerBridge.js
@@ -11,8 +11,9 @@
11 11
 define([
12 12
     'coweb/session/bayeux/cometd',
13 13
     'coweb/util/Promise',
14  
-    'coweb/util/lang'
15  
-], function(cometd, Promise, lang) {
  14
+    'coweb/util/lang',
  15
+	'coweb/topics'
  16
+], function(cometd, Promise, lang, topics) {
16 17
     /**
17 18
      * @constructor
18 19
      * @param {Object} args.listener ListenerInterface instance
@@ -36,6 +37,8 @@ define([
36 37
         this._updaterToken = null;
37 38
         // /session/sync/* subscription
38 39
         this._syncToken = null;
  40
+		// /session/admin/ subscription
  41
+		this._adminToken = null;
39 42
         // active requests for state
40 43
         this._stateReqs = {};
41 44
         // state of the join process
@@ -218,6 +221,7 @@ define([
218 221
      */
219 222
     proto.initiateUpdate = function() {
220 223
 		//the session id to the channel names.
  224
+		this.adminChannel = '/session/'+this._bridge.prepResponse.sessionid+'/admin';
221 225
 		this.syncChannel = '/session/'+this._bridge.prepResponse.sessionid+'/sync/*';
222 226
 		this.syncAppChannel = '/session/'+this._bridge.prepResponse.sessionid+'/sync/app';
223 227
 		this.syncEngineChannel = '/session/'+this._bridge.prepResponse.sessionid+'/sync/engine';
@@ -245,6 +249,8 @@ define([
245 249
             //this._syncToken = cometd.subscribe('/service/session/sync/*', 
246 250
 			this._syncToken = cometd.subscribe(this.syncChannel, 
247 251
                 this, '_onSessionSync');
  252
+			this._adminToken = cometd.subscribe(this.adminChannel, 
  253
+				this, '_onSessionAdmin');
248 254
             // start the joining process
249 255
             this._joinToken = cometd.subscribe('/service/session/join/*', 
250 256
                 this, '_onServiceSessionJoin');
@@ -468,6 +474,18 @@ define([
468 474
             console.warn('bayeux.ListenerBridge: received unknown sync ' + ch);
469 475
         }
470 476
     };
  477
+
  478
+	proto._onSessionAdmin = function(msg) {
  479
+		if(!msg.data.value.url) {
  480
+			return;
  481
+		}
  482
+		
  483
+		this._bridge.fireNavigationEvent(msg.data.value.url);
  484
+		
  485
+		setTimeout(function() {
  486
+			window.location = msg.data.value.url;
  487
+		}, 2000);
  488
+	};
471 489
     
472 490
     /**
473 491
      * Called to handle a /session/roster/ message. Forwards it to the 
41  servers/java/coweb-javascript/src/main/webapp/coweb/session/bayeux/SessionBridge.js
@@ -14,8 +14,9 @@ define([
14 14
     'coweb/session/bayeux/ListenerBridge',
15 15
     'coweb/util/Promise',
16 16
     'coweb/util/xhr',
17  
-	'org/requirejs/i18n!../../nls/messages'
18  
-], function(cometd, CowebExtension, ListenerBridge, Promise, xhr, messages) {
  17
+	'org/requirejs/i18n!../../nls/messages',
  18
+	'coweb/topics'
  19
+], function(cometd, CowebExtension, ListenerBridge, Promise, xhr, messages, topics) {
19 20
     /**
20 21
      * @constructor
21 22
      * @param {Boolean} args.debug True if in debug more, false if not
@@ -51,6 +52,8 @@ define([
51 52
         // info received from server
52 53
         this.prepResponse = null;
53 54
 
  55
+		this._navigateListeners = [];
  56
+
54 57
         // build listener bridge instance
55 58
         this._bridge = new ListenerBridge({
56 59
             debug: this._debug,
@@ -61,6 +64,31 @@ define([
61 64
     // save typing and lookup
62 65
     var proto = SessionBridge.prototype;
63 66
 
  67
+	proto.addNavigateListener = function(listener) {
  68
+		
  69
+		for(var i=0; i<this._navigateListeners; i++) {
  70
+			if(this._navigateListeners[i] === listener) {
  71
+				return;
  72
+			}
  73
+		}
  74
+			
  75
+	    this._navigateListeners.push(listener);
  76
+	};
  77
+	
  78
+	proto.fireNavigationEvent = function(obj) {
  79
+		for(var i=0; i<this._navigateListeners.length; i++) {
  80
+			this._navigateListeners[i].call(obj);
  81
+		}
  82
+	};
  83
+	
  84
+	proto.removeNavigateListener = function(listener) {
  85
+		for(var i=0; i<this._navigateListeners; i++) {
  86
+			if(this._navigateListeners[i] === listener) {
  87
+				this._navigateListeners.splice(i, 1);
  88
+				break;
  89
+			}
  90
+		}
  91
+	};
64 92
     /**
65 93
      * Destroys the instance. Voids all promises without resolution. Attempts
66 94
      * a disconnect from the server if not idle.
@@ -186,6 +214,15 @@ define([
186 214
         return this._joinPromise;
187 215
     };
188 216
 
  217
+	proto.navigate = function(url) {
  218
+		cometd.publish(this._bridge.adminChannel, {
  219
+			value: {
  220
+				url: url
  221
+			},
  222
+			topic: topics.ADMIN
  223
+		});
  224
+	};
  225
+	
189 226
     /**
190 227
      * Called on /meta/unsuccessful notification from the cometd client for
191 228
      * any error. Forces a disconnect to prevent attempts to reconnect with
4  servers/java/coweb-javascript/src/main/webapp/coweb/topics.js
@@ -35,7 +35,9 @@ define(function() {
35 35
         BUSY : p+'busy.change',
36 36
         // pausing and resuming topics
37 37
         PAUSE_TOPIC : p+'topics.pause',
38  
-        RESUME_TOPIC : p+'topics.resume'
  38
+        RESUME_TOPIC : p+'topics.resume',
  39
+
  40
+		ADMIN : p +'admin.navigate'
39 41
     };
40 42
 
41 43
 });

0 notes on commit 481b88b

Please sign in to comment.
Something went wrong with that request. Please try again.