@@ -138,6 +138,10 @@ function initTogetherJS() {
138138 // Remember, they were here first (that's why they're saying 'hello-back'),
139139 // so they keep their own name, but you need to change yours :)
140140 TogetherJS . hub . on ( "togetherjs.hello-back" , function ( msg ) {
141+ // guard against weird cases where someone is in your same session
142+ // but accidentally meandered to another page
143+ if ( ! msg . sameUrl ) return ;
144+
141145 var p = TogetherJS . require ( "peers" ) ;
142146
143147 var peerNames = p . getAllPeers ( ) . map ( function ( e ) { return e . name } ) ;
@@ -197,6 +201,10 @@ function initTogetherJS() {
197201 }
198202
199203 TogetherJS . hub . on ( "updateOutput" , function ( msg ) {
204+ // guard against weird cases where someone is in your same session
205+ // but accidentally meandered to another page
206+ if ( ! msg . sameUrl ) return ;
207+
200208 if ( isExecutingCode ) {
201209 return ;
202210 }
@@ -214,6 +222,10 @@ function initTogetherJS() {
214222 } ) ;
215223
216224 TogetherJS . hub . on ( "executeCode" , function ( msg ) {
225+ // guard against weird cases where someone is in your same session
226+ // but accidentally meandered to another page
227+ if ( ! msg . sameUrl ) return ;
228+
217229 if ( isExecutingCode ) {
218230 return ;
219231 }
@@ -229,6 +241,10 @@ function initTogetherJS() {
229241 } ) ;
230242
231243 TogetherJS . hub . on ( "hashchange" , function ( msg ) {
244+ // guard against weird cases where someone is in your same session
245+ // but accidentally meandered to another page
246+ if ( ! msg . sameUrl ) return ;
247+
232248 if ( isExecutingCode ) {
233249 return ;
234250 }
@@ -248,6 +264,10 @@ function initTogetherJS() {
248264 } ) ;
249265
250266 TogetherJS . hub . on ( "codemirror-edit" , function ( msg ) {
267+ // guard against weird cases where someone is in your same session
268+ // but accidentally meandered to another page
269+ if ( ! msg . sameUrl ) return ;
270+
251271 if ( ! $ ( "#codeInputWarnings" ) . data ( 'orig-html' ) ) { // set only once
252272 $ ( "#codeInputWarnings" ) . data ( 'orig-html' , $ ( "#codeInputWarnings" ) . html ( ) ) ;
253273 }
@@ -261,6 +281,10 @@ function initTogetherJS() {
261281 } ) ;
262282
263283 TogetherJS . hub . on ( "requestSync" , function ( msg ) {
284+ // guard against weird cases where someone is in your same session
285+ // but accidentally meandered to another page
286+ if ( ! msg . sameUrl ) return ;
287+
264288 if ( TogetherJS . running ) {
265289 TogetherJS . send ( { type : "myAppState" ,
266290 myAppState : getAppState ( ) ,
@@ -272,6 +296,10 @@ function initTogetherJS() {
272296 } ) ;
273297
274298 TogetherJS . hub . on ( "myAppState" , function ( msg ) {
299+ // guard against weird cases where someone is in your same session
300+ // but accidentally meandered to another page
301+ if ( ! msg . sameUrl ) return ;
302+
275303 // if we didn't explicitly request a sync, then don't do anything
276304 if ( ! togetherjsSyncRequested ) {
277305 return ;
@@ -327,10 +355,18 @@ function initTogetherJS() {
327355 } ) ;
328356
329357 TogetherJS . hub . on ( "codeInputScroll" , function ( msg ) {
358+ // guard against weird cases where someone is in your same session
359+ // but accidentally meandered to another page
360+ if ( ! msg . sameUrl ) return ;
361+
330362 $ ( codeMirrorScroller ) . scrollTop ( msg . scrollTop ) ;
331363 } ) ;
332364
333365 TogetherJS . hub . on ( "pyCodeOutputDivScroll" , function ( msg ) {
366+ // guard against weird cases where someone is in your same session
367+ // but accidentally meandered to another page
368+ if ( ! msg . sameUrl ) return ;
369+
334370 if ( myVisualizer ) {
335371 myVisualizer . domRoot . find ( '#pyCodeOutputDiv' ) . scrollTop ( msg . scrollTop ) ;
336372 }
0 commit comments