Browse Source

feat(ts) migrate Settings to TS

dev0
Yash 6 months ago
parent
commit
3d74fce959
No account linked to committer's email address
1 changed files with 20 additions and 11 deletions
  1. 20
    11
      modules/settings/Settings.ts

modules/settings/Settings.js → modules/settings/Settings.ts View File

6
 
6
 
7
 const logger = getLogger('modules/settings/Settings');
7
 const logger = getLogger('modules/settings/Settings');
8
 
8
 
9
-let _callStatsUserName;
9
+let _callStatsUserName: string | null = null;
10
 
10
 
11
-let _machineId;
11
+let _machineId: string | null = null;
12
 
12
 
13
 /**
13
 /**
14
  *
14
  *
15
  */
15
  */
16
-export default {
16
+export interface ISettings {
17
+    _storage: Storage;
18
+    readonly callStatsUserName: string;
19
+    init: (externalStorage?: Storage) => void;
20
+    readonly machineId: string;
21
+    sessionId: string;
22
+}
17
 
23
 
24
+const Settings: ISettings = {
18
     /**
25
     /**
19
      * The storage used to store the settings.
26
      * The storage used to store the settings.
20
      */
27
      */
26
      * @param {Storage|undefined} externalStorage - Object that implements the Storage interface. This object will be
33
      * @param {Storage|undefined} externalStorage - Object that implements the Storage interface. This object will be
27
      * used for storing data instead of jitsiLocalStorage if specified.
34
      * used for storing data instead of jitsiLocalStorage if specified.
28
      */
35
      */
29
-    init(externalStorage) {
36
+    init(externalStorage?: Storage): void {
30
         this._storage = externalStorage || jitsiLocalStorage;
37
         this._storage = externalStorage || jitsiLocalStorage;
31
     },
38
     },
32
 
39
 
34
      * Returns the ID to use for the purposes of stats, saved in localstorage as "callStatsUserName".
41
      * Returns the ID to use for the purposes of stats, saved in localstorage as "callStatsUserName".
35
      * @returns {string} fake username for callstats
42
      * @returns {string} fake username for callstats
36
      */
43
      */
37
-    get callStatsUserName() {
44
+    get callStatsUserName(): string {
38
         if (!_callStatsUserName) {
45
         if (!_callStatsUserName) {
39
             _callStatsUserName = this._storage.getItem('callStatsUserName');
46
             _callStatsUserName = this._storage.getItem('callStatsUserName');
40
             if (!_callStatsUserName) {
47
             if (!_callStatsUserName) {
50
      * Returns current machine id.
57
      * Returns current machine id.
51
      * @returns {string} machine id
58
      * @returns {string} machine id
52
      */
59
      */
53
-    get machineId() {
60
+    get machineId(): string {
54
         if (!_machineId) {
61
         if (!_machineId) {
55
             const amDid = this._storage.getItem('billingId');
62
             const amDid = this._storage.getItem('billingId');
56
 
63
 
64
             }
71
             }
65
         }
72
         }
66
 
73
 
67
-        return _machineId;
74
+        return _machineId!;
68
     },
75
     },
69
 
76
 
70
     /**
77
     /**
71
      * Returns current session id.
78
      * Returns current session id.
72
      * @returns {string} current session id
79
      * @returns {string} current session id
73
      */
80
      */
74
-    get sessionId() {
81
+    get sessionId(): string {
75
         // We may update sessionId in localStorage from another JitsiConference
82
         // We may update sessionId in localStorage from another JitsiConference
76
         // instance and that's why we should always re-read it.
83
         // instance and that's why we should always re-read it.
77
-        return this._storage.getItem('sessionId');
84
+        return this._storage.getItem('sessionId') || '';
78
     },
85
     },
79
 
86
 
80
     /**
87
     /**
81
      * Save current session id.
88
      * Save current session id.
82
      * @param {string} sessionId session id
89
      * @param {string} sessionId session id
83
      */
90
      */
84
-    set sessionId(sessionId) {
91
+    set sessionId(sessionId: string) {
85
         if (sessionId) {
92
         if (sessionId) {
86
             this._storage.setItem('sessionId', sessionId);
93
             this._storage.setItem('sessionId', sessionId);
87
         } else {
94
         } else {
106
  * Generate unique id.
113
  * Generate unique id.
107
  * @returns {string} random unique id
114
  * @returns {string} random unique id
108
  */
115
  */
109
-function generateJitsiMeetId() {
116
+function generateJitsiMeetId(): string {
110
     const jitsiMeetId = uuidv4().replaceAll('-', '');
117
     const jitsiMeetId = uuidv4().replaceAll('-', '');
111
 
118
 
112
     logger.log('generated id', jitsiMeetId);
119
     logger.log('generated id', jitsiMeetId);
113
 
120
 
114
     return jitsiMeetId;
121
     return jitsiMeetId;
115
 }
122
 }
123
+
124
+export default Settings;

Loading…
Cancel
Save