瀏覽代碼

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

master
Naman Jain 3 月之前
父節點
當前提交
9a4c7ae894
No account linked to committer's email address
共有 1 個文件被更改,包括 24 次插入12 次删除
  1. 24
    12
      modules/xmpp/strophe.emuc.ts

modules/xmpp/strophe.emuc.js → modules/xmpp/strophe.emuc.ts 查看文件

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

Loading…
取消
儲存