Bladeren bron

feat(TS) Migrate Strophe.emuc to TS (#2815)

master
Naman Jain 3 maanden geleden
bovenliggende
commit
9a4c7ae894
No account linked to committer's email address
1 gewijzigde bestanden met toevoegingen van 24 en 12 verwijderingen
  1. 24
    12
      modules/xmpp/strophe.emuc.ts

modules/xmpp/strophe.emuc.js → modules/xmpp/strophe.emuc.ts Bestand weergeven

7
 
7
 
8
 import ChatRoom from './ChatRoom';
8
 import ChatRoom from './ChatRoom';
9
 import { ConnectionPluginListenable } from './ConnectionPlugin';
9
 import { ConnectionPluginListenable } from './ConnectionPlugin';
10
+import XmppConnection from './XmppConnection';
11
+import XMPP from './xmpp';
10
 
12
 
11
 const logger = getLogger('modules/xmpp/strophe.emuc');
13
 const logger = getLogger('modules/xmpp/strophe.emuc');
12
 
14
 
14
  * MUC connection plugin.
16
  * MUC connection plugin.
15
  */
17
  */
16
 export default class MucConnectionPlugin extends ConnectionPluginListenable {
18
 export default class MucConnectionPlugin extends ConnectionPluginListenable {
19
+    /**
20
+     * XMPP connection instance
21
+     */
22
+    private xmpp: XMPP;
23
+
24
+    /**
25
+     * Map of room JIDs to ChatRoom instances
26
+     */
27
+    private rooms: { [roomJid: string]: ChatRoom; };
28
+
17
     /**
29
     /**
18
      *
30
      *
19
      * @param xmpp
31
      * @param xmpp
20
      */
32
      */
21
-    constructor(xmpp) {
33
+    constructor(xmpp: XMPP) {
22
         super();
34
         super();
23
         this.xmpp = xmpp;
35
         this.xmpp = xmpp;
24
         this.rooms = {};
36
         this.rooms = {};
28
      *
40
      *
29
      * @param connection
41
      * @param connection
30
      */
42
      */
31
-    init(connection) {
43
+    init(connection: XmppConnection): void {
32
         super.init(connection);
44
         super.init(connection);
33
 
45
 
34
         // add handlers (just once)
46
         // add handlers (just once)
54
      * @param password
66
      * @param password
55
      * @param options
67
      * @param options
56
      */
68
      */
57
-    createRoom(jid, password, options) {
69
+    createRoom(jid: string, password: string, options: any): ChatRoom {
58
         const roomJid = Strophe.getBareJidFromJid(jid);
70
         const roomJid = Strophe.getBareJidFromJid(jid);
59
 
71
 
60
         if (this.isRoomCreated(roomJid)) {
72
         if (this.isRoomCreated(roomJid)) {
77
      * @param {string} roomJid - The JID of the room.
89
      * @param {string} roomJid - The JID of the room.
78
      * @returns {boolean}
90
      * @returns {boolean}
79
      */
91
      */
80
-    isRoomCreated(roomJid) {
92
+    isRoomCreated(roomJid: string): boolean {
81
         return roomJid in this.rooms;
93
         return roomJid in this.rooms;
82
     }
94
     }
83
 
95
 
85
      *
97
      *
86
      * @param jid
98
      * @param jid
87
      */
99
      */
88
-    doLeave(jid) {
100
+    doLeave(jid: string): void {
89
         this.eventEmitter.emit(
101
         this.eventEmitter.emit(
90
             XMPPEvents.EMUC_ROOM_REMOVED, this.rooms[jid]);
102
             XMPPEvents.EMUC_ROOM_REMOVED, this.rooms[jid]);
91
         delete this.rooms[jid];
103
         delete this.rooms[jid];
95
      *
107
      *
96
      * @param pres
108
      * @param pres
97
      */
109
      */
98
-    onPresence(pres) {
110
+    onPresence(pres: Element): boolean {
99
         const from = pres.getAttribute('from');
111
         const from = pres.getAttribute('from');
100
 
112
 
101
         // What is this for? A workaround for something?
113
         // What is this for? A workaround for something?
124
      *
136
      *
125
      * @param pres
137
      * @param pres
126
      */
138
      */
127
-    onPresenceUnavailable(pres) {
139
+    onPresenceUnavailable(pres: Element): boolean {
128
         const from = pres.getAttribute('from');
140
         const from = pres.getAttribute('from');
129
         const room = this.rooms[Strophe.getBareJidFromJid(from)];
141
         const room = this.rooms[Strophe.getBareJidFromJid(from)];
130
 
142
 
141
      *
153
      *
142
      * @param pres
154
      * @param pres
143
      */
155
      */
144
-    onPresenceError(pres) {
156
+    onPresenceError(pres: Element): boolean {
145
         const from = pres.getAttribute('from');
157
         const from = pres.getAttribute('from');
146
         const room = this.rooms[Strophe.getBareJidFromJid(from)];
158
         const room = this.rooms[Strophe.getBareJidFromJid(from)];
147
 
159
 
158
      *
170
      *
159
      * @param msg
171
      * @param msg
160
      */
172
      */
161
-    onMessage(msg) {
173
+    onMessage(msg: Element): boolean {
162
         // FIXME: this is a hack. but jingle on muc makes nickchanges hard
174
         // FIXME: this is a hack. but jingle on muc makes nickchanges hard
163
         const from = msg.getAttribute('from');
175
         const from = msg.getAttribute('from');
164
         const room = this.rooms[Strophe.getBareJidFromJid(from)];
176
         const room = this.rooms[Strophe.getBareJidFromJid(from)];
176
      * TODO: Document
188
      * TODO: Document
177
      * @param iq
189
      * @param iq
178
      */
190
      */
179
-    onMute(iq) {
191
+    onMute(iq: Element): boolean {
180
         const from = iq.getAttribute('from');
192
         const from = iq.getAttribute('from');
181
         const room = this.rooms[Strophe.getBareJidFromJid(from)];
193
         const room = this.rooms[Strophe.getBareJidFromJid(from)];
182
 
194
 
194
      * TODO: Document
206
      * TODO: Document
195
      * @param iq
207
      * @param iq
196
      */
208
      */
197
-    onMuteVideo(iq) {
209
+    onMuteVideo(iq: Element): boolean {
198
         const from = iq.getAttribute('from');
210
         const from = iq.getAttribute('from');
199
         const room = this.rooms[Strophe.getBareJidFromJid(from)];
211
         const room = this.rooms[Strophe.getBareJidFromJid(from)];
200
 
212
 
213
      * @param iq The received iq.
225
      * @param iq The received iq.
214
      * @returns {boolean}
226
      * @returns {boolean}
215
      */
227
      */
216
-    onVisitors(iq) {
228
+    onVisitors(iq: Element): boolean {
217
         const from = iq.getAttribute('from');
229
         const from = iq.getAttribute('from');
218
         const room = this.rooms[Strophe.getBareJidFromJid(from)];
230
         const room = this.rooms[Strophe.getBareJidFromJid(from)];
219
 
231
 

Laden…
Annuleren
Opslaan