@@ -15,6 +15,13 @@ interface IdentityOption {
1515 name : string
1616 path : string
1717}
18+
19+ // If you're using the Ditto cloud these values can be found in the Ditto
20+ // portal, on your app settings page.
21+ const DITTO_APP_ID = uuidv4 ( )
22+ const DITTO_AUTH_URL = `https://${ DITTO_APP_ID } .cloud.ditto.live`
23+ const DITTO_WEBSOCKET_URL = `wss://${ DITTO_APP_ID } .cloud.ditto.live`
24+
1825const options : IdentityOption [ ] = [
1926 { path : '/path-development' , name : 'Development' } ,
2027 { path : '/path-online' , name : 'Online' } ,
@@ -29,25 +36,35 @@ const AppContainer: React.FC = () => {
2936 useOnlineIdentity ( )
3037 const [ currentPath , setCurrentPath ] = useState ( '/path-development' )
3138
32- const handleCreateDittoInstances = ( ) => {
39+ const handleCreateDittoInstances = async ( ) => {
3340 // Example of how to create a development instance
3441 const dittoDevelopment = new Ditto (
3542 createDevelopment ( { appID : 'live.ditto.example' , siteID : 1234 } ) ,
3643 '/path-development' ,
3744 )
45+ await dittoDevelopment . disableSyncWithV3 ( )
46+ dittoDevelopment . startSync ( )
3847
3948 // Example of how to create an online instance with authentication enabled
4049 const dittoOnline = new Ditto (
4150 createOnline (
4251 {
43- // If you're using the Ditto cloud this ID should be the app ID shown on your app settings page, on the portal.
44- appID : uuidv4 ( ) ,
45- // enableDittoCloudSync: true ,
52+ appID : DITTO_APP_ID ,
53+ enableDittoCloudSync : false ,
54+ customAuthURL : DITTO_AUTH_URL ,
4655 } ,
4756 '/path-online' ,
4857 ) ,
4958 '/path-online' ,
5059 )
60+ dittoOnline . updateTransportConfig ( ( config ) => {
61+ config . connect . websocketURLs = [ DITTO_WEBSOCKET_URL ]
62+ return config
63+ } )
64+ await dittoOnline . disableSyncWithV3 ( )
65+
66+ dittoOnline . startSync ( )
67+
5168 return [ dittoDevelopment , dittoOnline ]
5269 }
5370
@@ -79,6 +96,7 @@ const AppContainer: React.FC = () => {
7996 return < h1 > Loading</ h1 >
8097 }
8198 if ( error ) {
99+ if ( error ) console . error ( 'Error creating Ditto instances:' , error )
82100 return < h1 > Error: { JSON . stringify ( error ) } </ h1 >
83101 }
84102
0 commit comments