@diory/client-js 0.4.0 → 0.4.1

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.
@@ -1,6 +1,7 @@
1
1
  import { IConnectionObject, IDiosphere, IRoom, IRoomObject, IDiograph, IDiory, IDioryObject, IDataClient } from '@diory/types';
2
2
  import { IDioryClient } from '../types';
3
3
  declare class DioryClient implements IDioryClient {
4
+ dataClients: IDataClient[];
4
5
  diosphere: IDiosphere;
5
6
  diograph: IDiograph;
6
7
  room?: IRoom;
@@ -10,7 +10,8 @@ class DioryClient {
10
10
  constructor(dataClients) {
11
11
  this.initialiseDiosphere = async (connections) => {
12
12
  console.info('initialiseDiosphere: connections', connections);
13
- this.diosphere.initialise(connections);
13
+ const connectionClient = new connection_client_js_1.ConnectionClient(this.dataClients, connections);
14
+ this.diosphere.connect(connectionClient);
14
15
  await this.diosphere.getDiosphere();
15
16
  if (!Object.keys(this.diosphere.rooms)) {
16
17
  (0, addDefaultRoom_1.addDefaultRoom)(this.diosphere, connections);
@@ -23,7 +24,8 @@ class DioryClient {
23
24
  console.info('initialiseDiograph: room', roomObject);
24
25
  this.selectRoom(roomObject);
25
26
  if ((_a = this.room) === null || _a === void 0 ? void 0 : _a.connections) {
26
- this.diograph.initialise((_b = this.room) === null || _b === void 0 ? void 0 : _b.connections);
27
+ const connectionClient = new connection_client_js_1.ConnectionClient(this.dataClients, (_b = this.room) === null || _b === void 0 ? void 0 : _b.connections);
28
+ this.diograph.connect(connectionClient);
27
29
  await this.diograph.getDiograph();
28
30
  if (!Object.keys(this.diograph.diograph)) {
29
31
  (0, addDefaultDiograph_1.addDefaultDiograph)(this.diograph);
@@ -38,8 +40,9 @@ class DioryClient {
38
40
  this.focusDiory = (dioryObject) => {
39
41
  return (this.diory = this.diograph.getDiory(dioryObject));
40
42
  };
41
- this.diosphere = new diosphere_js_1.Diosphere(new connection_client_js_1.ConnectionClient(dataClients));
42
- this.diograph = new diograph_1.Diograph(new connection_client_js_1.ConnectionClient(dataClients));
43
+ this.dataClients = dataClients;
44
+ this.diosphere = new diosphere_js_1.Diosphere();
45
+ this.diograph = new diograph_1.Diograph();
43
46
  }
44
47
  }
45
48
  exports.DioryClient = DioryClient;
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@diory/client-js",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
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": "^0.4.0",
10
- "@diory/connection-client-js": "^0.4.0",
11
- "@diory/diosphere-js": "^0.4.0",
9
+ "@diograph/diograph": "^0.4.1",
10
+ "@diory/connection-client-js": "^0.4.1",
11
+ "@diory/diosphere-js": "^0.4.1",
12
12
  "path-browserify": "^1.0.1",
13
13
  "uuid": "8.3.2"
14
14
  },
15
15
  "devDependencies": {
16
- "@diory/types": "^0.4.0",
16
+ "@diory/types": "^0.4.2",
17
17
  "@types/jest": "^27.4.0",
18
18
  "@types/path-browserify": "^1.0.2",
19
19
  "@types/uuid": "8.3.2",
@@ -11,6 +11,7 @@ import {
11
11
  IDiory,
12
12
  IDioryObject,
13
13
  IDataClient,
14
+ IConnectionClient,
14
15
  } from '@diory/types'
15
16
 
16
17
  import { IDioryClient } from '../types'
@@ -19,20 +20,23 @@ import { addDefaultRoom } from '../utils/addDefaultRoom'
19
20
  import { addDefaultDiograph } from '../utils/addDefaultDiograph'
20
21
 
21
22
  class DioryClient implements IDioryClient {
23
+ dataClients: IDataClient[]
22
24
  diosphere: IDiosphere
23
25
  diograph: IDiograph
24
26
  room?: IRoom
25
27
  diory?: IDiory
26
28
 
27
29
  constructor(dataClients: IDataClient[]) {
28
- this.diosphere = new Diosphere(new ConnectionClient(dataClients))
29
- this.diograph = new Diograph(new ConnectionClient(dataClients))
30
+ this.dataClients = dataClients
31
+ this.diosphere = new Diosphere()
32
+ this.diograph = new Diograph()
30
33
  }
31
34
 
32
35
  initialiseDiosphere = async (connections: IConnectionObject[]): Promise<IDiosphere> => {
33
36
  console.info('initialiseDiosphere: connections', connections)
34
37
 
35
- this.diosphere.initialise(connections)
38
+ const connectionClient: IConnectionClient = new ConnectionClient(this.dataClients, connections)
39
+ this.diosphere.connect(connectionClient)
36
40
  await this.diosphere.getDiosphere()
37
41
 
38
42
  if (!Object.keys(this.diosphere.rooms)) {
@@ -49,7 +53,11 @@ class DioryClient implements IDioryClient {
49
53
  this.selectRoom(roomObject)
50
54
 
51
55
  if (this.room?.connections) {
52
- this.diograph.initialise(this.room?.connections)
56
+ const connectionClient: IConnectionClient = new ConnectionClient(
57
+ this.dataClients,
58
+ this.room?.connections,
59
+ )
60
+ this.diograph.connect(connectionClient)
53
61
  await this.diograph.getDiograph()
54
62
 
55
63
  if (!Object.keys(this.diograph.diograph)) {
@@ -1 +0,0 @@
1
- export declare function debounce(func: any, wait: number, immediate?: boolean): () => typeof func;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.debounce = void 0;
4
- function debounce(func, wait, immediate = false) {
5
- let timeout;
6
- // eslint-disable-next-line func-names
7
- return () => {
8
- // @ts-ignore
9
- const context = this;
10
- const args = arguments;
11
- // eslint-disable-next-line func-names
12
- const later = function () {
13
- timeout = null;
14
- if (!immediate)
15
- func.apply(context, args);
16
- };
17
- const callNow = immediate && !timeout;
18
- clearTimeout(timeout);
19
- timeout = setTimeout(later, wait);
20
- if (callNow)
21
- func.apply(context, args);
22
- };
23
- }
24
- exports.debounce = debounce;
@@ -1,18 +0,0 @@
1
- export function debounce(func: any, wait: number, immediate = false) {
2
- let timeout: any
3
- // eslint-disable-next-line func-names
4
- return (): typeof func => {
5
- // @ts-ignore
6
- const context = this
7
- const args = arguments
8
- // eslint-disable-next-line func-names
9
- const later = function () {
10
- timeout = null
11
- if (!immediate) func.apply(context, args)
12
- }
13
- const callNow = immediate && !timeout
14
- clearTimeout(timeout)
15
- timeout = setTimeout(later, wait)
16
- if (callNow) func.apply(context, args)
17
- }
18
- }