@@ -11,6 +11,7 @@ import { configs, slidesTitle } from '../env'
1111import { skipTransition } from '../logic/hmr'
1212import { getSlidePath } from '../logic/slides'
1313import { makeId } from '../logic/utils'
14+ import { syncDirections } from '../state'
1415import { initDrawingState } from '../state/drawings'
1516import { initSharedState , onPatch , patch } from '../state/shared'
1617
@@ -58,30 +59,28 @@ export default function setupRoot() {
5859 initDrawingState ( `${ slidesTitle } - drawings` )
5960
6061 const id = `${ location . origin } _${ makeId ( ) } `
62+ const syncType = computed ( ( ) => isPresenter . value ? 'presenter' : 'viewer' )
6163
6264 // update shared state
6365 function updateSharedState ( ) {
66+ const shouldSend = isPresenter . value
67+ ? syncDirections . value . presenterSend
68+ : syncDirections . value . viewerSend
69+
70+ if ( ! shouldSend )
71+ return
6472 if ( isNotesViewer . value || isPrintMode . value )
6573 return
66-
6774 // we allow Presenter mode, or Viewer mode from trusted origins to update the shared state
6875 if ( ! isPresenter . value && ! TRUST_ORIGINS . includes ( location . host . split ( ':' ) [ 0 ] ) )
6976 return
7077
71- if ( isPresenter . value ) {
72- patch ( 'page' , + currentSlideNo . value )
73- patch ( 'clicks' , clicksContext . value . current )
74- patch ( 'clicksTotal' , clicksContext . value . total )
75- }
76- else {
77- patch ( 'viewerPage' , + currentSlideNo . value )
78- patch ( 'viewerClicks' , clicksContext . value . current )
79- patch ( 'viewerClicksTotal' , clicksContext . value . total )
80- }
81-
78+ patch ( 'page' , + currentSlideNo . value )
79+ patch ( 'clicks' , clicksContext . value . current )
80+ patch ( 'clicksTotal' , clicksContext . value . total )
8281 patch ( 'lastUpdate' , {
8382 id,
84- type : isPresenter . value ? 'presenter' : 'viewer' ,
83+ type : syncType . value ,
8584 time : new Date ( ) . getTime ( ) ,
8685 } )
8786 }
@@ -90,17 +89,26 @@ export default function setupRoot() {
9089 watch ( clicksContext , updateSharedState )
9190
9291 onPatch ( ( state ) => {
92+ const shouldReceive = isPresenter . value
93+ ? syncDirections . value . presenterReceive
94+ : syncDirections . value . viewerReceive
95+ if ( ! shouldReceive )
96+ return
9397 if ( ! hasPrimarySlide . value || isPrintMode . value )
9498 return
95- if ( state . lastUpdate ?. type === 'presenter' && ( + state . page !== + currentSlideNo . value || + clicksContext . value . current !== + state . clicks ) ) {
96- skipTransition . value = false
97- router . replace ( {
98- path : getSlidePath ( state . page , isPresenter . value ) ,
99- query : {
100- ...router . currentRoute . value . query ,
101- clicks : state . clicks || 0 ,
102- } ,
103- } )
104- }
99+ if ( state . lastUpdate ?. type === syncType . value )
100+ return
101+ if ( ( + state . page === + currentSlideNo . value && + clicksContext . value . current === + state . clicks ) )
102+ return
103+ // if (state.lastUpdate?.type === 'presenter') {
104+ skipTransition . value = false
105+ router . replace ( {
106+ path : getSlidePath ( state . page , isPresenter . value ) ,
107+ query : {
108+ ...router . currentRoute . value . query ,
109+ clicks : state . clicks || 0 ,
110+ } ,
111+ } )
112+ // }
105113 } )
106114}
0 commit comments