Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions javascript-web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion javascript-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"preview": "vite preview"
},
"dependencies": {
"@dittolive/ditto": "^4.11.1",
"@dittolive/ditto": "^4.12.0-preview.2",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand Down
43 changes: 27 additions & 16 deletions javascript-web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import {
Ditto,
IdentityOnlinePlayground,
DittoConfig,
StoreObserver,
SyncSubscription,
Authenticator,
init,
} from '@dittolive/ditto';
import './App.css';
import DittoInfo from './components/DittoInfo';
import { useEffect, useRef, useState } from 'react';
import TaskList from './components/TaskList';

const identity: IdentityOnlinePlayground = {
type: 'onlinePlayground',
appID: import.meta.env.DITTO_APP_ID,
token: import.meta.env.DITTO_PLAYGROUND_TOKEN,
customAuthURL: import.meta.env.DITTO_AUTH_URL,
enableDittoCloudSync: false,
};
const databaseId = import.meta.env.DITTO_DATABASE_ID;
const devToken = import.meta.env.DITTO_DEV_TOKEN;
const authUrl = import.meta.env.DITTO_AUTH_URL;

export type Task = {
_id: string;
Expand Down Expand Up @@ -57,12 +54,26 @@
try {
// Create a new Ditto instance with the identity
// https://docs.ditto.live/sdk/latest/install-guides/js#integrating-ditto-and-starting-sync
ditto.current = new Ditto(identity);

// Initialize transport config
ditto.current.updateTransportConfig((config) => {
config.connect.websocketURLs = [import.meta.env.DITTO_WEBSOCKET_URL];
return config;
ditto.current = await Ditto.open(new DittoConfig(

Check failure on line 57 in javascript-web/src/App.tsx

View workflow job for this annotation

GitHub Actions / JavaScript Web Lint

Replace `new·DittoConfig(⏎··········databaseId,⏎·········` with `⏎··········new·DittoConfig(databaseId,`
databaseId,
{
type: 'server',
url: authUrl,
}

Check failure on line 62 in javascript-web/src/App.tsx

View workflow job for this annotation

GitHub Actions / JavaScript Web Lint

Insert `),`
));

Check failure on line 63 in javascript-web/src/App.tsx

View workflow job for this annotation

GitHub Actions / JavaScript Web Lint

Delete `)`
ditto.current.auth.setExpirationHandler(async (ditto, expirationSeconds) => {

Check failure on line 64 in javascript-web/src/App.tsx

View workflow job for this annotation

GitHub Actions / JavaScript Web Lint

'expirationSeconds' is defined but never used

Check failure on line 64 in javascript-web/src/App.tsx

View workflow job for this annotation

GitHub Actions / JavaScript Web Lint

Insert `⏎··········`
// Authenticate when token is expiring
try {
await ditto.auth.login(

Check failure on line 67 in javascript-web/src/App.tsx

View workflow job for this annotation

GitHub Actions / JavaScript Web Lint

Delete `··`
// Your development token, replace with your actual token

Check failure on line 68 in javascript-web/src/App.tsx

View workflow job for this annotation

GitHub Actions / JavaScript Web Lint

Delete `····`
devToken,

Check failure on line 69 in javascript-web/src/App.tsx

View workflow job for this annotation

GitHub Actions / JavaScript Web Lint

Delete `····`
// Use Authenticator.DEVELOPMENT_PROVIDER for playground, or your actual provider name

Check failure on line 70 in javascript-web/src/App.tsx

View workflow job for this annotation

GitHub Actions / JavaScript Web Lint

Replace `····················` with `················`
Authenticator.DEVELOPMENT_PROVIDER

Check failure on line 71 in javascript-web/src/App.tsx

View workflow job for this annotation

GitHub Actions / JavaScript Web Lint

Replace `····Authenticator.DEVELOPMENT_PROVIDER` with `Authenticator.DEVELOPMENT_PROVIDER,`
);
console.log("Authentication successful");
} catch (error) {
console.error("Authentication failed:", error);
}
});

// disable sync with v3 peers, required for DQL
Expand Down Expand Up @@ -202,8 +213,8 @@
<div className="h-full w-full flex flex-col container mx-auto items-center">
{error && <ErrorMessage error={error} />}
<DittoInfo
appId={identity.appID}
token={identity.token}
appId={databaseId}
token={devToken}
syncEnabled={syncActive}
onToggleSync={toggleSync}
isInitialized={isInitialized}
Expand Down
Loading