@diory/client-js 0.2.0-rc12 → 0.2.0-rc14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dioryClient/defaultDiograph.json +24 -0
- package/dist/dioryClient/defaultDiosphere.d.ts +21 -0
- package/dist/dioryClient/defaultDiosphere.js +26 -0
- package/dist/dioryClient/defaultDiosphere.json +23 -0
- package/dist/dioryClient/dioryClient.d.ts +9 -9
- package/dist/dioryClient/dioryClient.js +42 -35
- package/dist/dioryClient/getDefaultDiograph.d.ts +2 -0
- package/dist/dioryClient/getDefaultDiograph.js +17 -0
- package/dist/dioryClient/getDefaultDiosphere.d.ts +2 -0
- package/dist/dioryClient/getDefaultDiosphere.js +13 -0
- package/dist/types.d.ts +6 -6
- package/package.json +3 -3
- package/src/dioryClient/dioryClient.ts +66 -52
- package/src/dioryClient/getDefaultDiograph.ts +18 -0
- package/src/dioryClient/getDefaultDiosphere.ts +14 -0
- package/src/types.ts +6 -6
- package/tsconfig.json +3 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"/": {
|
|
3
|
+
"id": "welcome-root-diory"
|
|
4
|
+
},
|
|
5
|
+
"welcome-root-diory": {
|
|
6
|
+
"id": "welcome-root-diory",
|
|
7
|
+
"text": "Room",
|
|
8
|
+
"image": "",
|
|
9
|
+
"links": [
|
|
10
|
+
{
|
|
11
|
+
"id": "welcome-diory"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"modified": "2020-01-03T14:03:04.751Z"
|
|
15
|
+
},
|
|
16
|
+
"welcome-diory": {
|
|
17
|
+
"id": "welcome-diory",
|
|
18
|
+
"image": "",
|
|
19
|
+
"modified": "2020-01-03T14:03:04.751Z",
|
|
20
|
+
"text": "Welcome to Diory",
|
|
21
|
+
"latitude": 60.01366036242365,
|
|
22
|
+
"longitude": 20.007133483886722
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const diosphere: {
|
|
2
|
+
rooms: {
|
|
3
|
+
'/': {
|
|
4
|
+
id: string
|
|
5
|
+
created: string
|
|
6
|
+
modified: string
|
|
7
|
+
}
|
|
8
|
+
'welcome-room': {
|
|
9
|
+
id: string
|
|
10
|
+
text: string
|
|
11
|
+
doors: never[]
|
|
12
|
+
connections: {
|
|
13
|
+
id: string
|
|
14
|
+
client: string
|
|
15
|
+
address: string
|
|
16
|
+
}[]
|
|
17
|
+
created: string
|
|
18
|
+
modified: string
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.diosphere = void 0
|
|
4
|
+
exports.diosphere = {
|
|
5
|
+
rooms: {
|
|
6
|
+
'/': {
|
|
7
|
+
id: 'welcome-room',
|
|
8
|
+
created: '2024-03-24T14:56:21.243Z',
|
|
9
|
+
modified: '2024-03-24T14:56:21.243Z',
|
|
10
|
+
},
|
|
11
|
+
'welcome-room': {
|
|
12
|
+
id: 'welcome-room',
|
|
13
|
+
text: 'Wellcome',
|
|
14
|
+
doors: [],
|
|
15
|
+
connections: [
|
|
16
|
+
{
|
|
17
|
+
id: 'welcome-connection',
|
|
18
|
+
client: 'LocalClient',
|
|
19
|
+
address: 'public/welcome-room',
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
created: '2024-03-24T14:56:21.243Z',
|
|
23
|
+
modified: '2024-03-24T14:56:21.243Z',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"rooms": {
|
|
3
|
+
"/": {
|
|
4
|
+
"id": "welcome-room",
|
|
5
|
+
"created": "2024-03-24T14:56:21.243Z",
|
|
6
|
+
"modified": "2024-03-24T14:56:21.243Z"
|
|
7
|
+
},
|
|
8
|
+
"welcome-room": {
|
|
9
|
+
"id": "welcome-room",
|
|
10
|
+
"text": "Wellcome room",
|
|
11
|
+
"doors": [],
|
|
12
|
+
"connections": [
|
|
13
|
+
{
|
|
14
|
+
"id": "welcome-room",
|
|
15
|
+
"client": "LocalClient",
|
|
16
|
+
"address": "public/welcome-room"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"created": "2024-03-24T14:56:21.243Z",
|
|
20
|
+
"modified": "2024-03-24T14:56:21.243Z"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IConnectionObject, IDiosphere, IRoom, IRoomObject } from '@diory/diosphere-js';
|
|
2
|
-
import { IDiograph, IDiory, IDioryObject } from '@diograph/diograph';
|
|
1
|
+
import { IConnectionObject, IDiosphere, IDiosphereObject, IRoom, IRoomObject } from '@diory/diosphere-js';
|
|
2
|
+
import { IDiograph, IDiographObject, IDiory, IDioryObject } from '@diograph/diograph';
|
|
3
3
|
import { IDioryClient, IDataClient } from '../types';
|
|
4
4
|
declare class DioryClient implements IDioryClient {
|
|
5
5
|
dataClients: IDataClient[];
|
|
@@ -9,16 +9,16 @@ declare class DioryClient implements IDioryClient {
|
|
|
9
9
|
diograph: IDiograph;
|
|
10
10
|
diory?: IDiory;
|
|
11
11
|
constructor(dataClients: IDataClient[]);
|
|
12
|
-
initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>;
|
|
13
12
|
selectRoom: (roomObject: IRoomObject) => IRoom;
|
|
14
|
-
enterRoom: (roomObject: IRoomObject) => Promise<IRoom>;
|
|
15
|
-
focusDiory: (dioryObject: IDioryObject) => IDiory;
|
|
16
13
|
getDiosphereClients: (connections?: IConnectionObject[]) => import("../types").IConnectionClient[];
|
|
14
|
+
initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>;
|
|
15
|
+
getDiosphere: (connections?: IConnectionObject[]) => Promise<IDiosphereObject | undefined>;
|
|
16
|
+
saveDiosphere: (connections?: IConnectionObject[]) => Promise<IDiosphereObject>;
|
|
17
17
|
getDiographClients: (connections?: IConnectionObject[]) => import("../types").IConnectionClient[];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
getDiograph: (connections?: IConnectionObject[]) => Promise<
|
|
21
|
-
saveDiograph: (connections?: IConnectionObject[]) => Promise<
|
|
18
|
+
focusDiory: (dioryObject: IDioryObject) => IDiory;
|
|
19
|
+
initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
|
|
20
|
+
getDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject | undefined>;
|
|
21
|
+
saveDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject>;
|
|
22
22
|
generateDiograph: (connections?: IConnectionObject[]) => Promise<IDiograph>;
|
|
23
23
|
}
|
|
24
24
|
export { DioryClient };
|
|
@@ -4,45 +4,34 @@ exports.DioryClient = void 0;
|
|
|
4
4
|
const diosphere_js_1 = require("@diory/diosphere-js");
|
|
5
5
|
const diograph_1 = require("@diograph/diograph");
|
|
6
6
|
const getConnectionClients_1 = require("../utils/getConnectionClients");
|
|
7
|
+
const getDefaultDiosphere_1 = require("./getDefaultDiosphere");
|
|
8
|
+
const getDefaultDiograph_1 = require("./getDefaultDiograph");
|
|
7
9
|
class DioryClient {
|
|
8
10
|
constructor(dataClients) {
|
|
9
11
|
this.dataClients = [];
|
|
10
12
|
this.connections = [];
|
|
11
|
-
this.initialise = async (connections) => {
|
|
12
|
-
console.info('initialise', connections);
|
|
13
|
-
this.connections = connections;
|
|
14
|
-
this.diosphere.resetRooms();
|
|
15
|
-
console.info(this.diosphere);
|
|
16
|
-
return this;
|
|
17
|
-
};
|
|
18
13
|
this.selectRoom = (roomObject) => {
|
|
19
14
|
return (this.room = this.diosphere.getRoom(roomObject));
|
|
20
15
|
};
|
|
21
|
-
this.enterRoom = async (roomObject) => {
|
|
22
|
-
console.info('enterRoom', roomObject);
|
|
23
|
-
this.selectRoom(roomObject);
|
|
24
|
-
this.diograph.resetDiograph();
|
|
25
|
-
await this.getDiograph();
|
|
26
|
-
console.info(this.room);
|
|
27
|
-
return this.room;
|
|
28
|
-
};
|
|
29
|
-
this.focusDiory = (dioryObject) => {
|
|
30
|
-
return (this.diory = this.diograph.getDiory(dioryObject));
|
|
31
|
-
};
|
|
32
16
|
this.getDiosphereClients = (connections) => {
|
|
33
17
|
return (0, getConnectionClients_1.getConnectionClients)(this.dataClients, connections !== null && connections !== void 0 ? connections : this.connections);
|
|
34
18
|
};
|
|
35
|
-
this.
|
|
19
|
+
this.initialiseDiosphere = async (connections) => {
|
|
36
20
|
var _a;
|
|
37
|
-
|
|
21
|
+
console.info('initialiseDiosphere', connections);
|
|
22
|
+
this.connections = connections;
|
|
23
|
+
this.diosphere.resetRooms();
|
|
24
|
+
const diosphereObject = (_a = (await this.getDiosphere())) !== null && _a !== void 0 ? _a : (0, getDefaultDiosphere_1.getDefaultDiosphere)(connections);
|
|
25
|
+
this.diosphere.addDiosphere(diosphereObject);
|
|
26
|
+
this.selectRoom({ id: '/' });
|
|
27
|
+
return this.diosphere;
|
|
38
28
|
};
|
|
39
29
|
this.getDiosphere = async (connections) => {
|
|
40
30
|
console.info('getDiosphere', connections);
|
|
31
|
+
let diosphereObject;
|
|
41
32
|
await Promise.all(this.getDiosphereClients(connections).map(async (connectionClient) => {
|
|
42
33
|
try {
|
|
43
|
-
|
|
44
|
-
this.diosphere.addDiosphere(diosphereObject);
|
|
45
|
-
this.selectRoom({ id: '/' });
|
|
34
|
+
diosphereObject = await connectionClient.getDiosphere();
|
|
46
35
|
console.info(this.diosphere.toObject());
|
|
47
36
|
}
|
|
48
37
|
catch (error) {
|
|
@@ -50,41 +39,59 @@ class DioryClient {
|
|
|
50
39
|
}
|
|
51
40
|
return;
|
|
52
41
|
}));
|
|
53
|
-
return
|
|
42
|
+
return diosphereObject;
|
|
54
43
|
};
|
|
55
44
|
this.saveDiosphere = async (connections) => {
|
|
56
45
|
console.info('saveDiosphere', connections);
|
|
46
|
+
const diosphereObject = this.diosphere.toObject();
|
|
57
47
|
await Promise.all(this.getDiosphereClients(connections).map(async (connectionClient) => {
|
|
58
|
-
await connectionClient.saveDiosphere(
|
|
59
|
-
console.info(
|
|
48
|
+
await connectionClient.saveDiosphere(diosphereObject);
|
|
49
|
+
console.info(diosphereObject);
|
|
60
50
|
return;
|
|
61
51
|
}));
|
|
62
|
-
return
|
|
52
|
+
return diosphereObject;
|
|
53
|
+
};
|
|
54
|
+
this.getDiographClients = (connections) => {
|
|
55
|
+
var _a;
|
|
56
|
+
return (0, getConnectionClients_1.getConnectionClients)(this.dataClients, connections !== null && connections !== void 0 ? connections : (_a = this.room) === null || _a === void 0 ? void 0 : _a.connections);
|
|
57
|
+
};
|
|
58
|
+
this.focusDiory = (dioryObject) => {
|
|
59
|
+
return (this.diory = this.diograph.getDiory(dioryObject));
|
|
60
|
+
};
|
|
61
|
+
this.initialiseDiograph = async (roomObject) => {
|
|
62
|
+
var _a;
|
|
63
|
+
console.info('initialiseDiograph', roomObject);
|
|
64
|
+
this.selectRoom(roomObject);
|
|
65
|
+
this.diograph.resetDiograph();
|
|
66
|
+
const diographObject = (_a = (await this.getDiograph())) !== null && _a !== void 0 ? _a : (0, getDefaultDiograph_1.getDefaultDiograph)();
|
|
67
|
+
this.diograph.addDiograph(diographObject);
|
|
68
|
+
this.focusDiory({ id: '/' });
|
|
69
|
+
return this.diograph;
|
|
63
70
|
};
|
|
64
71
|
this.getDiograph = async (connections) => {
|
|
65
72
|
console.info('getDiograph', connections);
|
|
73
|
+
let diographObject;
|
|
66
74
|
await Promise.all(this.getDiographClients(connections).map(async (connectionClient) => {
|
|
67
75
|
try {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.focusDiory({ id: '/' });
|
|
71
|
-
console.info(this.diograph.toObject());
|
|
76
|
+
diographObject = await connectionClient.getDiograph();
|
|
77
|
+
console.info(diographObject);
|
|
72
78
|
}
|
|
73
79
|
catch (error) {
|
|
74
80
|
console.error(error);
|
|
75
81
|
}
|
|
76
82
|
return;
|
|
77
83
|
}));
|
|
78
|
-
return
|
|
84
|
+
return diographObject;
|
|
79
85
|
};
|
|
80
86
|
this.saveDiograph = async (connections) => {
|
|
81
87
|
console.info('saveDiograph', connections);
|
|
88
|
+
const diographObject = this.diograph.toObject();
|
|
82
89
|
await Promise.all(this.getDiographClients(connections).map(async (connectionClient) => {
|
|
83
|
-
await connectionClient.saveDiograph(
|
|
84
|
-
console.info(
|
|
90
|
+
await connectionClient.saveDiograph(diographObject);
|
|
91
|
+
console.info(diographObject);
|
|
85
92
|
return;
|
|
86
93
|
}));
|
|
87
|
-
return
|
|
94
|
+
return diographObject;
|
|
88
95
|
};
|
|
89
96
|
this.generateDiograph = async (connections) => {
|
|
90
97
|
console.info('generateDiograph', connections);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultDiograph = void 0;
|
|
4
|
+
const diograph_1 = require("@diograph/diograph");
|
|
5
|
+
const getDefaultDiograph = () => {
|
|
6
|
+
const diograph = new diograph_1.Diograph();
|
|
7
|
+
const diory = diograph.addDiory({
|
|
8
|
+
text: 'Welcome to Diory',
|
|
9
|
+
latlng: '60.01366036242365, 20.007133483886722',
|
|
10
|
+
});
|
|
11
|
+
diograph.addDiory({
|
|
12
|
+
text: 'Room root',
|
|
13
|
+
links: [{ id: diory.id }],
|
|
14
|
+
}, '/');
|
|
15
|
+
return diograph.toObject();
|
|
16
|
+
};
|
|
17
|
+
exports.getDefaultDiograph = getDefaultDiograph;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultDiosphere = void 0;
|
|
4
|
+
const diosphere_js_1 = require("@diory/diosphere-js");
|
|
5
|
+
const getDefaultDiosphere = (connections) => {
|
|
6
|
+
const diosphere = new diosphere_js_1.Diosphere();
|
|
7
|
+
diosphere.addRoom({
|
|
8
|
+
text: 'Welcome room',
|
|
9
|
+
connections,
|
|
10
|
+
}, '/');
|
|
11
|
+
return diosphere.toObject();
|
|
12
|
+
};
|
|
13
|
+
exports.getDefaultDiosphere = getDefaultDiosphere;
|
package/dist/types.d.ts
CHANGED
|
@@ -48,13 +48,13 @@ export interface IDioryClient {
|
|
|
48
48
|
room?: IRoom;
|
|
49
49
|
diograph: IDiograph;
|
|
50
50
|
diory?: IDiory;
|
|
51
|
-
initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>;
|
|
52
51
|
selectRoom: (roomObject: IRoomObject) => IRoom;
|
|
53
|
-
|
|
52
|
+
getDiosphere: () => Promise<IDiosphereObject | undefined>;
|
|
53
|
+
saveDiosphere: () => Promise<IDiosphereObject>;
|
|
54
|
+
initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>;
|
|
54
55
|
focusDiory: (dioryObject: IDioryObject) => IDiory;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
saveDiograph: () => Promise<IDiograph>;
|
|
56
|
+
getDiograph: () => Promise<IDiographObject | undefined>;
|
|
57
|
+
saveDiograph: () => Promise<IDiographObject>;
|
|
58
|
+
initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
|
|
59
59
|
generateDiograph: () => Promise<IDiograph>;
|
|
60
60
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diory/client-js",
|
|
3
|
-
"version": "0.2.0-
|
|
3
|
+
"version": "0.2.0-rc14",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": "Olli-Pekka Pohjola <op@diory.me>, Jouni Alanen <jouni@diory.me>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@diograph/diograph": "
|
|
9
|
+
"@diograph/diograph": "0.3.0-rc16",
|
|
10
10
|
"@diograph/folder-generator": "^0.3.0-rc3",
|
|
11
|
-
"@diory/diosphere-js": "
|
|
11
|
+
"@diory/diosphere-js": "0.2.6-rc4",
|
|
12
12
|
"path-browserify": "^1.0.1",
|
|
13
13
|
"uuid": "8.3.2"
|
|
14
14
|
},
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
Diosphere,
|
|
3
|
+
IConnectionObject,
|
|
4
|
+
IDiosphere,
|
|
5
|
+
IDiosphereObject,
|
|
6
|
+
IRoom,
|
|
7
|
+
IRoomObject,
|
|
8
|
+
} from '@diory/diosphere-js'
|
|
9
|
+
import { Diograph, IDiograph, IDiographObject, IDiory, IDioryObject } from '@diograph/diograph'
|
|
3
10
|
|
|
4
11
|
import { IDioryClient, IDataClient } from '../types'
|
|
5
12
|
import { getConnectionClients } from '../utils/getConnectionClients'
|
|
6
13
|
|
|
14
|
+
import { getDefaultDiosphere } from './getDefaultDiosphere'
|
|
15
|
+
import { getDefaultDiograph } from './getDefaultDiograph'
|
|
16
|
+
|
|
7
17
|
class DioryClient implements IDioryClient {
|
|
8
18
|
dataClients: IDataClient[] = []
|
|
9
19
|
connections: IConnectionObject[] = []
|
|
@@ -22,112 +32,116 @@ class DioryClient implements IDioryClient {
|
|
|
22
32
|
this.diograph.saveDiograph = this.saveDiograph
|
|
23
33
|
}
|
|
24
34
|
|
|
25
|
-
initialise = async (connections: IConnectionObject[]): Promise<IDioryClient> => {
|
|
26
|
-
console.info('initialise', connections)
|
|
27
|
-
|
|
28
|
-
this.connections = connections
|
|
29
|
-
this.diosphere.resetRooms()
|
|
30
|
-
console.info(this.diosphere)
|
|
31
|
-
|
|
32
|
-
return this
|
|
33
|
-
}
|
|
34
|
-
|
|
35
35
|
selectRoom = (roomObject: IRoomObject): IRoom => {
|
|
36
36
|
return (this.room = this.diosphere.getRoom(roomObject))
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
enterRoom = async (roomObject: IRoomObject): Promise<IRoom> => {
|
|
40
|
-
console.info('enterRoom', roomObject)
|
|
41
|
-
|
|
42
|
-
this.selectRoom(roomObject)
|
|
43
|
-
this.diograph.resetDiograph()
|
|
44
|
-
await this.getDiograph()
|
|
45
|
-
console.info(this.room)
|
|
46
|
-
|
|
47
|
-
return this.room as IRoom
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
focusDiory = (dioryObject: IDioryObject): IDiory => {
|
|
51
|
-
return (this.diory = this.diograph.getDiory(dioryObject))
|
|
52
|
-
}
|
|
53
|
-
|
|
54
39
|
getDiosphereClients = (connections?: IConnectionObject[]) => {
|
|
55
40
|
return getConnectionClients(this.dataClients, connections ?? this.connections)
|
|
56
41
|
}
|
|
57
42
|
|
|
58
|
-
|
|
59
|
-
|
|
43
|
+
initialiseDiosphere = async (connections: IConnectionObject[]): Promise<IDiosphere> => {
|
|
44
|
+
console.info('initialiseDiosphere', connections)
|
|
45
|
+
this.connections = connections
|
|
46
|
+
|
|
47
|
+
this.diosphere.resetRooms()
|
|
48
|
+
const diosphereObject = (await this.getDiosphere()) ?? getDefaultDiosphere(connections)
|
|
49
|
+
this.diosphere.addDiosphere(diosphereObject)
|
|
50
|
+
|
|
51
|
+
this.selectRoom({ id: '/' })
|
|
52
|
+
|
|
53
|
+
return this.diosphere
|
|
60
54
|
}
|
|
61
55
|
|
|
62
|
-
getDiosphere = async (
|
|
56
|
+
getDiosphere = async (
|
|
57
|
+
connections?: IConnectionObject[],
|
|
58
|
+
): Promise<IDiosphereObject | undefined> => {
|
|
63
59
|
console.info('getDiosphere', connections)
|
|
60
|
+
|
|
61
|
+
let diosphereObject
|
|
64
62
|
await Promise.all(
|
|
65
63
|
this.getDiosphereClients(connections).map(async (connectionClient) => {
|
|
66
64
|
try {
|
|
67
|
-
|
|
68
|
-
this.diosphere.addDiosphere(diosphereObject)
|
|
69
|
-
this.selectRoom({ id: '/' })
|
|
65
|
+
diosphereObject = await connectionClient.getDiosphere()
|
|
70
66
|
console.info(this.diosphere.toObject())
|
|
71
67
|
} catch (error) {
|
|
72
68
|
console.error(error)
|
|
73
69
|
}
|
|
74
|
-
|
|
75
70
|
return
|
|
76
71
|
}),
|
|
77
72
|
)
|
|
78
73
|
|
|
79
|
-
return
|
|
74
|
+
return diosphereObject
|
|
80
75
|
}
|
|
81
76
|
|
|
82
|
-
saveDiosphere = async (connections?: IConnectionObject[]): Promise<
|
|
77
|
+
saveDiosphere = async (connections?: IConnectionObject[]): Promise<IDiosphereObject> => {
|
|
83
78
|
console.info('saveDiosphere', connections)
|
|
84
79
|
|
|
80
|
+
const diosphereObject = this.diosphere.toObject()
|
|
85
81
|
await Promise.all(
|
|
86
82
|
this.getDiosphereClients(connections).map(async (connectionClient) => {
|
|
87
|
-
await connectionClient.saveDiosphere(
|
|
88
|
-
console.info(
|
|
89
|
-
|
|
83
|
+
await connectionClient.saveDiosphere(diosphereObject)
|
|
84
|
+
console.info(diosphereObject)
|
|
90
85
|
return
|
|
91
86
|
}),
|
|
92
87
|
)
|
|
93
88
|
|
|
94
|
-
return
|
|
89
|
+
return diosphereObject
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getDiographClients = (connections?: IConnectionObject[]) => {
|
|
93
|
+
return getConnectionClients(this.dataClients, connections ?? this.room?.connections)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
focusDiory = (dioryObject: IDioryObject): IDiory => {
|
|
97
|
+
return (this.diory = this.diograph.getDiory(dioryObject))
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
initialiseDiograph = async (roomObject: IRoomObject): Promise<IDiograph> => {
|
|
101
|
+
console.info('initialiseDiograph', roomObject)
|
|
102
|
+
this.selectRoom(roomObject)
|
|
103
|
+
|
|
104
|
+
this.diograph.resetDiograph()
|
|
105
|
+
const diographObject = (await this.getDiograph()) ?? getDefaultDiograph()
|
|
106
|
+
this.diograph.addDiograph(diographObject)
|
|
107
|
+
|
|
108
|
+
this.focusDiory({ id: '/' })
|
|
109
|
+
|
|
110
|
+
return this.diograph
|
|
95
111
|
}
|
|
96
112
|
|
|
97
|
-
getDiograph = async (connections?: IConnectionObject[]): Promise<
|
|
113
|
+
getDiograph = async (connections?: IConnectionObject[]): Promise<IDiographObject | undefined> => {
|
|
98
114
|
console.info('getDiograph', connections)
|
|
99
115
|
|
|
116
|
+
let diographObject
|
|
100
117
|
await Promise.all(
|
|
101
118
|
this.getDiographClients(connections).map(async (connectionClient) => {
|
|
102
119
|
try {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.focusDiory({ id: '/' })
|
|
106
|
-
console.info(this.diograph.toObject())
|
|
120
|
+
diographObject = await connectionClient.getDiograph()
|
|
121
|
+
console.info(diographObject)
|
|
107
122
|
} catch (error) {
|
|
108
123
|
console.error(error)
|
|
109
124
|
}
|
|
110
|
-
|
|
111
125
|
return
|
|
112
126
|
}),
|
|
113
127
|
)
|
|
114
128
|
|
|
115
|
-
return
|
|
129
|
+
return diographObject
|
|
116
130
|
}
|
|
117
131
|
|
|
118
|
-
saveDiograph = async (connections?: IConnectionObject[]): Promise<
|
|
132
|
+
saveDiograph = async (connections?: IConnectionObject[]): Promise<IDiographObject> => {
|
|
119
133
|
console.info('saveDiograph', connections)
|
|
120
134
|
|
|
135
|
+
const diographObject = this.diograph.toObject()
|
|
121
136
|
await Promise.all(
|
|
122
137
|
this.getDiographClients(connections).map(async (connectionClient) => {
|
|
123
|
-
await connectionClient.saveDiograph(
|
|
124
|
-
console.info(
|
|
125
|
-
|
|
138
|
+
await connectionClient.saveDiograph(diographObject)
|
|
139
|
+
console.info(diographObject)
|
|
126
140
|
return
|
|
127
141
|
}),
|
|
128
142
|
)
|
|
129
143
|
|
|
130
|
-
return
|
|
144
|
+
return diographObject
|
|
131
145
|
}
|
|
132
146
|
|
|
133
147
|
generateDiograph = async (connections?: IConnectionObject[]): Promise<IDiograph> => {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Diograph, IDiographObject } from '@diograph/diograph'
|
|
2
|
+
|
|
3
|
+
export const getDefaultDiograph = (): IDiographObject => {
|
|
4
|
+
const diograph = new Diograph()
|
|
5
|
+
const diory = diograph.addDiory({
|
|
6
|
+
text: 'Welcome to Diory',
|
|
7
|
+
latlng: '60.01366036242365, 20.007133483886722',
|
|
8
|
+
})
|
|
9
|
+
diograph.addDiory(
|
|
10
|
+
{
|
|
11
|
+
text: 'Room root',
|
|
12
|
+
links: [{ id: diory.id }],
|
|
13
|
+
},
|
|
14
|
+
'/',
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
return diograph.toObject()
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Diosphere, IConnectionObject, IDiosphereObject } from '@diory/diosphere-js'
|
|
2
|
+
|
|
3
|
+
export const getDefaultDiosphere = (connections: IConnectionObject[]): IDiosphereObject => {
|
|
4
|
+
const diosphere = new Diosphere()
|
|
5
|
+
diosphere.addRoom(
|
|
6
|
+
{
|
|
7
|
+
text: 'Welcome room',
|
|
8
|
+
connections,
|
|
9
|
+
},
|
|
10
|
+
'/',
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
return diosphere.toObject()
|
|
14
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -58,13 +58,13 @@ export interface IDioryClient {
|
|
|
58
58
|
room?: IRoom
|
|
59
59
|
diograph: IDiograph
|
|
60
60
|
diory?: IDiory
|
|
61
|
-
initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>
|
|
62
61
|
selectRoom: (roomObject: IRoomObject) => IRoom
|
|
63
|
-
|
|
62
|
+
getDiosphere: () => Promise<IDiosphereObject | undefined>
|
|
63
|
+
saveDiosphere: () => Promise<IDiosphereObject>
|
|
64
|
+
initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>
|
|
64
65
|
focusDiory: (dioryObject: IDioryObject) => IDiory
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
saveDiograph: () => Promise<IDiograph>
|
|
66
|
+
getDiograph: () => Promise<IDiographObject | undefined>
|
|
67
|
+
saveDiograph: () => Promise<IDiographObject>
|
|
68
|
+
initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>
|
|
69
69
|
generateDiograph: () => Promise<IDiograph>
|
|
70
70
|
}
|
package/tsconfig.json
CHANGED