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

Loading…
Cancel
Save