@equinor/fusion-framework-module-signalr 5.0.0 → 5.0.2
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/CHANGELOG.md +117 -95
- package/dist/esm/SignalRModule.js.map +1 -1
- package/dist/esm/SignalRModuleConfigurator.js.map +1 -1
- package/dist/esm/SignalRModuleProvider.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/Topic.js.map +1 -1
- package/dist/esm/lib/utils/configure-from-framework.js.map +1 -1
- package/dist/esm/lib/utils/enable-signalr.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/SignalRModule.d.ts +3 -3
- package/dist/types/SignalRModuleConfigurator.d.ts +3 -3
- package/dist/types/SignalRModuleProvider.d.ts +2 -2
- package/dist/types/lib/Topic.d.ts +1 -1
- package/dist/types/lib/utils/configure-from-framework.d.ts +3 -3
- package/dist/types/lib/utils/enable-signalr.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +7 -7
- package/src/SignalRModule.ts +12 -12
- package/src/SignalRModuleConfigurator.ts +54 -54
- package/src/SignalRModuleProvider.ts +67 -67
- package/src/index.ts +6 -6
- package/src/lib/Topic.ts +30 -30
- package/src/lib/utils/configure-from-framework.ts +28 -28
- package/src/lib/utils/enable-signalr.ts +34 -34
- package/src/version.ts +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Module } from '@equinor/fusion-framework-module';
|
|
2
|
-
import { ISignalRConfigurator } from './SignalRModuleConfigurator';
|
|
3
|
-
import { ISignalRProvider } from './SignalRModuleProvider';
|
|
1
|
+
import type { Module } from '@equinor/fusion-framework-module';
|
|
2
|
+
import { type ISignalRConfigurator } from './SignalRModuleConfigurator';
|
|
3
|
+
import { type ISignalRProvider } from './SignalRModuleProvider';
|
|
4
4
|
export type SignalRModuleKey = 'signalR';
|
|
5
5
|
export declare const moduleKey: SignalRModuleKey;
|
|
6
6
|
export type SignalRModule = Module<SignalRModuleKey, ISignalRProvider, ISignalRConfigurator>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AnyModule, ModuleConfigBuilder, ModuleInitializerArgs } from '@equinor/fusion-framework-module';
|
|
2
|
-
import { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
|
|
3
|
-
import { IHttpConnectionOptions, LogLevel } from '@microsoft/signalr';
|
|
1
|
+
import { type AnyModule, ModuleConfigBuilder, type ModuleInitializerArgs } from '@equinor/fusion-framework-module';
|
|
2
|
+
import type { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
|
|
3
|
+
import type { IHttpConnectionOptions, LogLevel } from '@microsoft/signalr';
|
|
4
4
|
export interface ISignalRConfigurator {
|
|
5
5
|
/** add configuration for hub connection */
|
|
6
6
|
addHub(name: string, config: SignalRHubConfig | Promise<SignalRHubConfig>): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HubConnection } from '@microsoft/signalr';
|
|
1
|
+
import { type HubConnection } from '@microsoft/signalr';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
-
import { SignalRConfig } from './SignalRModuleConfigurator';
|
|
3
|
+
import type { SignalRConfig } from './SignalRModuleConfigurator';
|
|
4
4
|
import { Topic } from './lib/Topic';
|
|
5
5
|
export interface ISignalRProvider {
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { MsalModule } from '@equinor/fusion-framework-module-msal';
|
|
2
|
-
import { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
|
|
3
|
-
import { SignalRModuleConfigBuilder } from '../../SignalRModuleConfigurator';
|
|
1
|
+
import type { MsalModule } from '@equinor/fusion-framework-module-msal';
|
|
2
|
+
import type { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
|
|
3
|
+
import type { SignalRModuleConfigBuilder } from '../../SignalRModuleConfigurator';
|
|
4
4
|
export declare const configureFromFramework: (args: {
|
|
5
5
|
name: string;
|
|
6
6
|
service: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IModulesConfigurator } from '@equinor/fusion-framework-module';
|
|
2
|
-
import { SignalRModuleConfigBuilderCallback } from '../../SignalRModuleConfigurator';
|
|
2
|
+
import type { SignalRModuleConfigBuilderCallback } from '../../SignalRModuleConfigurator';
|
|
3
3
|
export interface enableSignalR {
|
|
4
4
|
(configurator: IModulesConfigurator<any, any>, name: string, cb: SignalRModuleConfigBuilderCallback): void;
|
|
5
5
|
(configurator: IModulesConfigurator<any, any>, name: string, options: {
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.0.
|
|
1
|
+
export declare const version = "5.0.2";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-module-signalr",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "dist/esm/index.js",
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
"rxjs": "^7.8.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"typescript": "^5.
|
|
39
|
-
"@equinor/fusion-framework-module": "^4.
|
|
40
|
-
"@equinor/fusion-framework-module
|
|
38
|
+
"typescript": "^5.8.2",
|
|
39
|
+
"@equinor/fusion-framework-module-msal": "^4.0.2",
|
|
40
|
+
"@equinor/fusion-framework-module": "^4.3.7"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@equinor/fusion-framework-module
|
|
44
|
-
"@equinor/fusion-framework-module-service-discovery": "^8.0.
|
|
45
|
-
"@equinor/fusion-framework-module": "^4.
|
|
43
|
+
"@equinor/fusion-framework-module": "^4.3.7",
|
|
44
|
+
"@equinor/fusion-framework-module-service-discovery": "^8.0.8",
|
|
45
|
+
"@equinor/fusion-framework-module-msal": "^4.0.2"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"@equinor/fusion-framework-module-service-discovery": {
|
package/src/SignalRModule.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Module } from '@equinor/fusion-framework-module';
|
|
2
|
-
import { ISignalRConfigurator, SignalRConfigurator } from './SignalRModuleConfigurator';
|
|
1
|
+
import type { Module } from '@equinor/fusion-framework-module';
|
|
2
|
+
import { type ISignalRConfigurator, SignalRConfigurator } from './SignalRModuleConfigurator';
|
|
3
3
|
|
|
4
|
-
import { ISignalRProvider, SignalRModuleProvider } from './SignalRModuleProvider';
|
|
4
|
+
import { type ISignalRProvider, SignalRModuleProvider } from './SignalRModuleProvider';
|
|
5
5
|
|
|
6
6
|
export type SignalRModuleKey = 'signalR';
|
|
7
7
|
|
|
@@ -10,18 +10,18 @@ export const moduleKey: SignalRModuleKey = 'signalR';
|
|
|
10
10
|
export type SignalRModule = Module<SignalRModuleKey, ISignalRProvider, ISignalRConfigurator>;
|
|
11
11
|
|
|
12
12
|
export const module: SignalRModule = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
name: moduleKey,
|
|
14
|
+
configure: () => new SignalRConfigurator(),
|
|
15
|
+
initialize: async (init) => {
|
|
16
|
+
const config = await (init.config as SignalRConfigurator).createConfig(init);
|
|
17
|
+
return new SignalRModuleProvider(config);
|
|
18
|
+
},
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
export default module;
|
|
22
22
|
|
|
23
23
|
declare module '@equinor/fusion-framework-module' {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
interface Modules {
|
|
25
|
+
signalR: SignalRModule;
|
|
26
|
+
}
|
|
27
27
|
}
|
|
@@ -1,94 +1,94 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
type AnyModule,
|
|
3
|
+
ModuleConfigBuilder,
|
|
4
|
+
type ModuleInitializerArgs,
|
|
5
5
|
} from '@equinor/fusion-framework-module';
|
|
6
6
|
|
|
7
|
-
import { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
|
|
8
|
-
import { IHttpConnectionOptions, LogLevel } from '@microsoft/signalr';
|
|
7
|
+
import type { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
|
|
8
|
+
import type { IHttpConnectionOptions, LogLevel } from '@microsoft/signalr';
|
|
9
9
|
|
|
10
10
|
export interface ISignalRConfigurator {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/** add configuration for hub connection */
|
|
12
|
+
addHub(name: string, config: SignalRHubConfig | Promise<SignalRHubConfig>): void;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/** add callback for building config on init */
|
|
15
|
+
onCreateConfig(cb: SignalRModuleConfigBuilderCallback): void;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/** configuration callback */
|
|
19
19
|
export type SignalRModuleConfigBuilderCallback<TDeps = unknown> = (
|
|
20
|
-
|
|
20
|
+
builder: SignalRModuleConfigBuilder<TDeps>,
|
|
21
21
|
) => void | Promise<void>;
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Configuration for hub connection
|
|
25
25
|
*/
|
|
26
26
|
export type SignalRHubConfig = {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
/** connection endpoint */
|
|
28
|
+
url: string;
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
/** connection options */
|
|
31
|
+
options: Omit<IHttpConnectionOptions, 'httpClient'>;
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
/** reconnect when connection lost */
|
|
34
|
+
automaticReconnect?: boolean;
|
|
35
|
+
logLevel?: LogLevel;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* Configuration for creating SignalR provider
|
|
40
40
|
*/
|
|
41
41
|
export type SignalRConfig = {
|
|
42
|
-
|
|
42
|
+
hubs: Record<string, SignalRHubConfig>;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* builder utility class for generating configuration
|
|
47
47
|
*/
|
|
48
48
|
export class SignalRModuleConfigBuilder<
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
TDeps extends AnyModule[] | unknown = unknown,
|
|
50
|
+
// TODO - use BaseConfigBuilder
|
|
51
51
|
> extends ModuleConfigBuilder<TDeps, ISignalRConfigurator> {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
async addHub(name: string, config: SignalRHubConfig) {
|
|
53
|
+
this._config.addHub(name, config);
|
|
54
|
+
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export class SignalRConfigurator implements ISignalRConfigurator {
|
|
58
|
-
|
|
58
|
+
#builderCallbacks: Array<SignalRModuleConfigBuilderCallback> = [];
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
#hubs: Record<string, SignalRHubConfig> = {};
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
/**
|
|
63
|
+
* register SignalR hub configuration.
|
|
64
|
+
*/
|
|
65
|
+
public addHub(name: string, config: SignalRHubConfig) {
|
|
66
|
+
this.#hubs[name] = config;
|
|
67
|
+
}
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
/**
|
|
70
|
+
* add callback for building config on when configurator is creating config.
|
|
71
|
+
* {@link SignalRConfigurator.createConfig}
|
|
72
|
+
*/
|
|
73
|
+
public onCreateConfig<T>(cb: SignalRModuleConfigBuilderCallback<T>): void {
|
|
74
|
+
this.#builderCallbacks.push(cb);
|
|
75
|
+
}
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return { hubs: this.#hubs };
|
|
77
|
+
/**
|
|
78
|
+
* normally executed in `init` phase of module, which creates configuration to the module provider.
|
|
79
|
+
* cycles threw all registered configuration builders.
|
|
80
|
+
* await all registered hub configurations.
|
|
81
|
+
*/
|
|
82
|
+
public async createConfig(
|
|
83
|
+
init: ModuleInitializerArgs<ISignalRConfigurator, [ServiceDiscoveryModule]>,
|
|
84
|
+
): Promise<SignalRConfig> {
|
|
85
|
+
/** trigger all builder callbacks */
|
|
86
|
+
for (const cb of this.#builderCallbacks) {
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
+
const builder = new SignalRModuleConfigBuilder<[ServiceDiscoveryModule]>(init, this);
|
|
89
|
+
await Promise.resolve(cb(builder));
|
|
93
90
|
}
|
|
91
|
+
|
|
92
|
+
return { hubs: this.#hubs };
|
|
93
|
+
}
|
|
94
94
|
}
|
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import { HubConnectionBuilder, HubConnection, AbortError } from '@microsoft/signalr';
|
|
1
|
+
import { HubConnectionBuilder, type HubConnection, AbortError } from '@microsoft/signalr';
|
|
2
2
|
import { Observable, shareReplay } from 'rxjs';
|
|
3
3
|
|
|
4
|
-
import { SignalRConfig } from './SignalRModuleConfigurator';
|
|
4
|
+
import type { SignalRConfig } from './SignalRModuleConfigurator';
|
|
5
5
|
|
|
6
6
|
import { Topic } from './lib/Topic';
|
|
7
7
|
|
|
8
8
|
export interface ISignalRProvider {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
/**
|
|
10
|
+
* connect to SignalR hub
|
|
11
|
+
* re-use existing connections and close connection when nobody is listening
|
|
12
|
+
*/
|
|
13
|
+
connect<T>(ubId: string, methodName: string): Topic<T>;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export class SignalRModuleProvider implements ISignalRProvider {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
#config: SignalRConfig;
|
|
18
|
+
#hubConnections: Record<string, Observable<HubConnection>> = {};
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
constructor(config: SignalRConfig) {
|
|
21
|
+
this.#config = config;
|
|
22
|
+
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
public connect<T>(hubId: string, methodName: string): Topic<T> {
|
|
25
|
+
return new Topic<T>(methodName, this._createHubConnection(hubId));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
protected _createHubConnection(hubId: string): Observable<HubConnection> {
|
|
29
|
+
const LOG_LEVEL_CRITICAL = 5;
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (hubId in this.#hubConnections) {
|
|
32
|
-
return this.#hubConnections[hubId];
|
|
33
|
-
}
|
|
34
|
-
const config = this.#config.hubs[hubId];
|
|
35
|
-
if (!config) {
|
|
36
|
-
throw Error(`could not find any configuration for hub [${hubId}]`);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
this.#hubConnections[hubId] = new Observable<HubConnection>((observer) => {
|
|
40
|
-
const builder = new HubConnectionBuilder().withUrl(config.url, {
|
|
41
|
-
...config.options,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
config.automaticReconnect && builder.withAutomaticReconnect();
|
|
45
|
-
|
|
46
|
-
builder.configureLogging(config.logLevel || LOG_LEVEL_CRITICAL);
|
|
47
|
-
|
|
48
|
-
const connection = builder.build();
|
|
49
|
-
|
|
50
|
-
connection
|
|
51
|
-
.start()
|
|
52
|
-
.then(() => {
|
|
53
|
-
observer.next(connection);
|
|
54
|
-
})
|
|
55
|
-
.catch((error: unknown) => {
|
|
56
|
-
if (error instanceof AbortError) {
|
|
57
|
-
// Omit AbortError
|
|
58
|
-
} else {
|
|
59
|
-
throw error;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const teardown = () => {
|
|
64
|
-
connection.stop();
|
|
65
|
-
observer.complete();
|
|
66
|
-
delete this.#hubConnections[hubId];
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
return teardown;
|
|
70
|
-
}).pipe(
|
|
71
|
-
shareReplay({
|
|
72
|
-
/** only emit last connection when new subscriber connects */
|
|
73
|
-
bufferSize: 1,
|
|
74
|
-
/** when no subscribers, teardown observable */
|
|
75
|
-
refCount: true,
|
|
76
|
-
}),
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
return this.#hubConnections[hubId];
|
|
31
|
+
if (hubId in this.#hubConnections) {
|
|
32
|
+
return this.#hubConnections[hubId];
|
|
80
33
|
}
|
|
34
|
+
const config = this.#config.hubs[hubId];
|
|
35
|
+
if (!config) {
|
|
36
|
+
throw Error(`could not find any configuration for hub [${hubId}]`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this.#hubConnections[hubId] = new Observable<HubConnection>((observer) => {
|
|
40
|
+
const builder = new HubConnectionBuilder().withUrl(config.url, {
|
|
41
|
+
...config.options,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
config.automaticReconnect && builder.withAutomaticReconnect();
|
|
45
|
+
|
|
46
|
+
builder.configureLogging(config.logLevel || LOG_LEVEL_CRITICAL);
|
|
47
|
+
|
|
48
|
+
const connection = builder.build();
|
|
49
|
+
|
|
50
|
+
connection
|
|
51
|
+
.start()
|
|
52
|
+
.then(() => {
|
|
53
|
+
observer.next(connection);
|
|
54
|
+
})
|
|
55
|
+
.catch((error: unknown) => {
|
|
56
|
+
if (error instanceof AbortError) {
|
|
57
|
+
// Omit AbortError
|
|
58
|
+
} else {
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const teardown = () => {
|
|
64
|
+
connection.stop();
|
|
65
|
+
observer.complete();
|
|
66
|
+
delete this.#hubConnections[hubId];
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return teardown;
|
|
70
|
+
}).pipe(
|
|
71
|
+
shareReplay({
|
|
72
|
+
/** only emit last connection when new subscriber connects */
|
|
73
|
+
bufferSize: 1,
|
|
74
|
+
/** when no subscribers, teardown observable */
|
|
75
|
+
refCount: true,
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
return this.#hubConnections[hubId];
|
|
80
|
+
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
export default SignalRModuleProvider;
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
ISignalRConfigurator,
|
|
3
|
+
SignalRConfigurator,
|
|
4
|
+
SignalRConfig,
|
|
5
|
+
SignalRHubConfig,
|
|
6
|
+
SignalRModuleConfigBuilder,
|
|
7
|
+
SignalRModuleConfigBuilderCallback,
|
|
8
8
|
} from './SignalRModuleConfigurator';
|
|
9
9
|
|
|
10
10
|
export { ISignalRProvider, SignalRModuleProvider } from './SignalRModuleProvider';
|
package/src/lib/Topic.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { HubConnection } from '@microsoft/signalr';
|
|
1
|
+
import type { HubConnection } from '@microsoft/signalr';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
|
|
4
4
|
export class Topic<T> extends Observable<T> {
|
|
5
|
-
|
|
5
|
+
connection: HubConnection | undefined;
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
constructor(
|
|
8
|
+
public topic: string,
|
|
9
|
+
public hubConnection: Observable<HubConnection>,
|
|
10
|
+
) {
|
|
11
|
+
super((subscriber) => {
|
|
12
|
+
const hubConnectionSubscription = hubConnection.subscribe((connection) => {
|
|
13
|
+
const cb = subscriber.next.bind(subscriber);
|
|
14
|
+
connection.on(topic, cb);
|
|
15
|
+
subscriber.add(() => connection.off(topic, cb));
|
|
16
|
+
this.connection = connection;
|
|
17
|
+
});
|
|
18
|
+
subscriber.add(() => {
|
|
19
|
+
hubConnectionSubscription.unsubscribe();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
this.connection.send(this.topic, args);
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
public send(...args: any[]): void {
|
|
26
|
+
if (!this.connection) {
|
|
27
|
+
throw new Error('No hub connection awaitable');
|
|
30
28
|
}
|
|
29
|
+
this.connection.send(this.topic, args);
|
|
30
|
+
}
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
return this.connection?.invoke(this.topic, args);
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
public invoke<T>(...args: any[]): Promise<T> {
|
|
34
|
+
if (!this.connection) {
|
|
35
|
+
throw new Error('No hub connection awaitable');
|
|
38
36
|
}
|
|
37
|
+
return this.connection?.invoke(this.topic, args);
|
|
38
|
+
}
|
|
39
39
|
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { MsalModule } from '@equinor/fusion-framework-module-msal';
|
|
2
|
-
import { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
|
|
1
|
+
import type { MsalModule } from '@equinor/fusion-framework-module-msal';
|
|
2
|
+
import type { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
|
|
3
3
|
|
|
4
|
-
import { SignalRModuleConfigBuilder } from '../../SignalRModuleConfigurator';
|
|
4
|
+
import type { SignalRModuleConfigBuilder } from '../../SignalRModuleConfigurator';
|
|
5
5
|
|
|
6
6
|
export const configureFromFramework = async (
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
args: { name: string; service: string; path: string },
|
|
8
|
+
builder: SignalRModuleConfigBuilder<[MsalModule, ServiceDiscoveryModule]>,
|
|
9
9
|
) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
10
|
+
const authProvider = await builder.requireInstance('auth');
|
|
11
|
+
const serviceDiscovery = await builder.requireInstance('serviceDiscovery');
|
|
12
|
+
const service = await serviceDiscovery.resolveService(args.name);
|
|
13
|
+
builder.addHub(args.name, {
|
|
14
|
+
url: new URL(args.path, service.uri).toString(),
|
|
15
|
+
options: {
|
|
16
|
+
accessTokenFactory: async () => {
|
|
17
|
+
if (!service.scopes) {
|
|
18
|
+
throw Error(
|
|
19
|
+
`service [${service.name}] does not have authentication scopes, please configure an endpoint with scopes`,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
const token = await authProvider.acquireAccessToken({
|
|
23
|
+
scopes: service.scopes ?? service.defaultScopes,
|
|
24
|
+
});
|
|
25
|
+
if (!token) {
|
|
26
|
+
throw Error('failed to acquire access token');
|
|
27
|
+
}
|
|
28
|
+
return token;
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
automaticReconnect: true,
|
|
32
|
+
});
|
|
33
33
|
};
|