1 |
|
2 |
|
3 | import { MqttOverWSProvider, MqttProviderOptions } from './MqttOverWSProvider';
|
4 | import { Signer, Credentials } from '@aws-amplify/core';
|
5 |
|
6 | const SERVICE_NAME = 'iotdevicegateway';
|
7 |
|
8 | export interface AWSIoTProviderOptions extends MqttProviderOptions {
|
9 | aws_pubsub_region?: string;
|
10 | aws_pubsub_endpoint?: string;
|
11 | }
|
12 |
|
13 | export class AWSIoTProvider extends MqttOverWSProvider {
|
14 | constructor(options: AWSIoTProviderOptions = {}) {
|
15 | super(options);
|
16 | }
|
17 |
|
18 | protected get region(): string | undefined {
|
19 | return this.options['aws_pubsub_region'];
|
20 | }
|
21 |
|
22 | public getProviderName() {
|
23 | return 'AWSIoTProvider';
|
24 | }
|
25 |
|
26 | protected get endpoint() {
|
27 | return (async () => {
|
28 | const endpoint = this.options.aws_pubsub_endpoint;
|
29 |
|
30 | const serviceInfo = {
|
31 | service: SERVICE_NAME,
|
32 | region: this.region,
|
33 | };
|
34 | const {
|
35 | accessKeyId: access_key,
|
36 | secretAccessKey: secret_key,
|
37 | sessionToken: session_token,
|
38 | } = await Credentials.get();
|
39 |
|
40 | const result = Signer.signUrl(
|
41 | endpoint,
|
42 | { access_key, secret_key, session_token },
|
43 | serviceInfo
|
44 | );
|
45 |
|
46 | return result;
|
47 | })();
|
48 | }
|
49 | }
|
50 |
|
\ | No newline at end of file |