Browse Source

refactor. number convert

matrixbirds 4 years ago
parent
commit
69beb13077
4 changed files with 40 additions and 43 deletions
  1. 4
    0
      lib/RtcEngine.native.d.ts
  2. 17
    20
      lib/RtcEngine.native.js
  3. 1
    1
      lib/RtcEngine.native.js.map
  4. 18
    22
      src/RtcEngine.native.ts

+ 4
- 0
lib/RtcEngine.native.d.ts View File

319
      * @ignore Uint32ToInt32
319
      * @ignore Uint32ToInt32
320
      */
320
      */
321
     private static Uint32ToInt32;
321
     private static Uint32ToInt32;
322
+    /**
323
+     * @ignore Int32ToUint32
324
+     */
325
+    private static Int32ToUint32;
322
     /**
326
     /**
323
      * mute specified remote video stream.
327
      * mute specified remote video stream.
324
      *
328
      *

+ 17
- 20
lib/RtcEngine.native.js View File

81
             if (react_native_1.Platform.OS === 'android') {
81
             if (react_native_1.Platform.OS === 'android') {
82
                 const _uid = this.Uint32ToInt32(uid);
82
                 const _uid = this.Uint32ToInt32(uid);
83
                 let result = yield Agora.getUserInfoByUid(_uid);
83
                 let result = yield Agora.getUserInfoByUid(_uid);
84
-                result.uid = this.Uint32ToInt32(result.uid);
84
+                result.uid = this.Int32ToUint32(result.uid);
85
                 return result;
85
                 return result;
86
             }
86
             }
87
             return Agora.getUserInfoByUid(uid);
87
             return Agora.getUserInfoByUid(uid);
98
         return tslib_1.__awaiter(this, void 0, void 0, function* () {
98
         return tslib_1.__awaiter(this, void 0, void 0, function* () {
99
             if (react_native_1.Platform.OS === 'android') {
99
             if (react_native_1.Platform.OS === 'android') {
100
                 let result = yield Agora.getUserInfoByUserAccount(userAccount);
100
                 let result = yield Agora.getUserInfoByUserAccount(userAccount);
101
-                result.uid = this.Uint32ToInt32(result.uid);
101
+                result.uid = this.Int32ToUint32(result.uid);
102
                 return result;
102
                 return result;
103
             }
103
             }
104
             return Agora.getUserInfoByUserAccount(userAccount);
104
             return Agora.getUserInfoByUserAccount(userAccount);
217
             'localUserRegistered'
217
             'localUserRegistered'
218
         ].indexOf(eventType) != -1) {
218
         ].indexOf(eventType) != -1) {
219
             AgoraEventEmitter.addListener(`${RtcEngine.AG_PREFIX}${eventType}`, (args) => {
219
             AgoraEventEmitter.addListener(`${RtcEngine.AG_PREFIX}${eventType}`, (args) => {
220
-                const uint32_uid = new Uint32Array(1);
221
-                uint32_uid[0] = args.uid;
222
-                args.uid = uint32_uid[0];
220
+                args.uid = this.Int32ToUint32(args.uid);
223
                 // convert int32 streamId to uint32 
221
                 // convert int32 streamId to uint32 
224
                 if (args.streamId) {
222
                 if (args.streamId) {
225
-                    const uint32_streamId = new Uint32Array(1);
226
-                    uint32_streamId[0] = args.streamId;
227
-                    args.streamId = uint32_streamId[0];
223
+                    args.streamId = this.Int32ToUint32(args.streamId);
228
                 }
224
                 }
229
                 listener(args);
225
                 listener(args);
230
             });
226
             });
232
         }
228
         }
233
         if (['userInfoUpdated'].indexOf(eventType) != -1) {
229
         if (['userInfoUpdated'].indexOf(eventType) != -1) {
234
             AgoraEventEmitter.addListener(`${RtcEngine.AG_PREFIX}${eventType}`, (args) => {
230
             AgoraEventEmitter.addListener(`${RtcEngine.AG_PREFIX}${eventType}`, (args) => {
235
-                const uint32_uid = new Uint32Array(1);
236
-                uint32_uid[0] = args.uid;
237
-                args.uid = uint32_uid[0];
238
-                const uint32_peer_uid = new Uint32Array(1);
239
-                uint32_peer_uid[0] = args.peer.uid;
240
-                args.peer.uid = uint32_peer_uid[0];
231
+                args.uid = this.Int32ToUint32(args.uid);
232
+                args.peer.uid = this.Int32ToUint32(args.peer.uid);
241
                 listener(args);
233
                 listener(args);
242
             });
234
             });
243
             return;
235
             return;
245
         if (['audioVolumeIndication'].indexOf(eventType) != -1) {
237
         if (['audioVolumeIndication'].indexOf(eventType) != -1) {
246
             AgoraEventEmitter.addListener(`${RtcEngine.AG_PREFIX}${eventType}`, (args) => {
238
             AgoraEventEmitter.addListener(`${RtcEngine.AG_PREFIX}${eventType}`, (args) => {
247
                 args.speakers.map((speaker) => {
239
                 args.speakers.map((speaker) => {
248
-                    const uint32_uid = new Uint32Array(1);
249
-                    uint32_uid[0] = speaker.uid;
250
-                    return Object.assign({}, speaker, { uid: uint32_uid[0] });
240
+                    const uid = this.Int32ToUint32(speaker.uid);
241
+                    return Object.assign({}, speaker, { uid });
251
                 });
242
                 });
252
                 listener(args);
243
                 listener(args);
253
             });
244
             });
260
             'videoTransportStatsOfUid',
251
             'videoTransportStatsOfUid',
261
         ].indexOf(eventType) != -1) {
252
         ].indexOf(eventType) != -1) {
262
             AgoraEventEmitter.addListener(`${RtcEngine.AG_PREFIX}${eventType}`, (args) => {
253
             AgoraEventEmitter.addListener(`${RtcEngine.AG_PREFIX}${eventType}`, (args) => {
263
-                const uint32_uid = new Uint32Array(1);
264
-                uint32_uid[0] = args.stats.uid;
265
-                args.stats.uid = uint32_uid[0];
254
+                args.stats.uid = this.Int32ToUint32(args.stats.uid);
266
                 listener(args);
255
                 listener(args);
267
             });
256
             });
268
             return;
257
             return;
469
         int32[0] = num;
458
         int32[0] = num;
470
         return int32[0];
459
         return int32[0];
471
     }
460
     }
461
+    /**
462
+     * @ignore Int32ToUint32
463
+     */
464
+    static Int32ToUint32(num) {
465
+        const uint32 = new Uint32Array(1);
466
+        uint32[0] = num;
467
+        return uint32[0];
468
+    }
472
     /**
469
     /**
473
      * mute specified remote video stream.
470
      * mute specified remote video stream.
474
      *
471
      *

+ 1
- 1
lib/RtcEngine.native.js.map
File diff suppressed because it is too large
View File


+ 18
- 22
src/RtcEngine.native.ts View File

118
         if (Platform.OS === 'android') {
118
         if (Platform.OS === 'android') {
119
             const _uid = this.Uint32ToInt32(uid);
119
             const _uid = this.Uint32ToInt32(uid);
120
             let result = await Agora.getUserInfoByUid(_uid);
120
             let result = await Agora.getUserInfoByUid(_uid);
121
-            result.uid = this.Uint32ToInt32(result.uid);
121
+            result.uid = this.Int32ToUint32(result.uid);
122
             return result;
122
             return result;
123
         }
123
         }
124
         return Agora.getUserInfoByUid(uid);
124
         return Agora.getUserInfoByUid(uid);
134
     public static async getUserInfoByUserAccount(userAccount: string): Promise<AgoraUserInfo> {
134
     public static async getUserInfoByUserAccount(userAccount: string): Promise<AgoraUserInfo> {
135
         if (Platform.OS === 'android') {
135
         if (Platform.OS === 'android') {
136
             let result = await Agora.getUserInfoByUserAccount(userAccount);
136
             let result = await Agora.getUserInfoByUserAccount(userAccount);
137
-            result.uid = this.Uint32ToInt32(result.uid);
137
+            result.uid = this.Int32ToUint32(result.uid);
138
             return result;
138
             return result;
139
         }
139
         }
140
         return Agora.getUserInfoByUserAccount(userAccount);
140
         return Agora.getUserInfoByUserAccount(userAccount);
253
             'localUserRegistered'
253
             'localUserRegistered'
254
         ].indexOf(eventType) != -1) {
254
         ].indexOf(eventType) != -1) {
255
             AgoraEventEmitter.addListener(`${RtcEngine.AG_PREFIX}${eventType}`, (args) => {
255
             AgoraEventEmitter.addListener(`${RtcEngine.AG_PREFIX}${eventType}`, (args) => {
256
-                const uint32_uid = new Uint32Array(1);
257
-                uint32_uid[0] = args.uid;
258
-                args.uid = uint32_uid[0];
259
-
256
+                args.uid = this.Int32ToUint32(args.uid);
260
                 // convert int32 streamId to uint32 
257
                 // convert int32 streamId to uint32 
261
                 if(args.streamId) {
258
                 if(args.streamId) {
262
-                    const uint32_streamId = new Uint32Array(1);
263
-                    uint32_streamId[0] = args.streamId;
264
-                    args.streamId = uint32_streamId[0];
259
+                    args.streamId = this.Int32ToUint32(args.streamId);
265
                 }
260
                 }
266
                 listener(args);
261
                 listener(args);
267
             });
262
             });
270
 
265
 
271
         if (['userInfoUpdated'].indexOf(eventType) != -1) {
266
         if (['userInfoUpdated'].indexOf(eventType) != -1) {
272
             AgoraEventEmitter.addListener(`${RtcEngine.AG_PREFIX}${eventType}`, (args) => {
267
             AgoraEventEmitter.addListener(`${RtcEngine.AG_PREFIX}${eventType}`, (args) => {
273
-                const uint32_uid = new Uint32Array(1);
274
-                uint32_uid[0] = args.uid;
275
-                args.uid = uint32_uid[0];
276
-
277
-                const uint32_peer_uid = new Uint32Array(1);
278
-                uint32_peer_uid[0] = args.peer.uid;
279
-                args.peer.uid = uint32_peer_uid[0];
268
+                args.uid = this.Int32ToUint32(args.uid);
269
+                args.peer.uid = this.Int32ToUint32(args.peer.uid);
280
                 listener(args);
270
                 listener(args);
281
             });
271
             });
282
             return;
272
             return;
285
         if (['audioVolumeIndication'].indexOf(eventType) != -1) {
275
         if (['audioVolumeIndication'].indexOf(eventType) != -1) {
286
             AgoraEventEmitter.addListener(`${RtcEngine.AG_PREFIX}${eventType}`, (args) => {
276
             AgoraEventEmitter.addListener(`${RtcEngine.AG_PREFIX}${eventType}`, (args) => {
287
                 args.speakers.map((speaker: any) => {
277
                 args.speakers.map((speaker: any) => {
288
-                    const uint32_uid = new Uint32Array(1);
289
-                    uint32_uid[0] = speaker.uid;
278
+                    const uid = this.Int32ToUint32(speaker.uid);
290
                     return {
279
                     return {
291
                         ...speaker,
280
                         ...speaker,
292
-                        uid: uint32_uid[0]
281
+                        uid
293
                     }
282
                     }
294
                 })
283
                 })
295
                 listener(args);
284
                 listener(args);
304
             'videoTransportStatsOfUid',   
293
             'videoTransportStatsOfUid',   
305
         ].indexOf(eventType) != -1) {
294
         ].indexOf(eventType) != -1) {
306
             AgoraEventEmitter.addListener(`${RtcEngine.AG_PREFIX}${eventType}`, (args) => {
295
             AgoraEventEmitter.addListener(`${RtcEngine.AG_PREFIX}${eventType}`, (args) => {
307
-                const uint32_uid = new Uint32Array(1);
308
-                uint32_uid[0] = args.stats.uid;
309
-                args.stats.uid = uint32_uid[0];
296
+                args.stats.uid = this.Int32ToUint32(args.stats.uid);
310
                 listener(args);
297
                 listener(args);
311
             });
298
             });
312
             return;
299
             return;
536
         return int32[0];
523
         return int32[0];
537
     }
524
     }
538
 
525
 
526
+    /**
527
+     * @ignore Int32ToUint32
528
+     */
529
+    private static Int32ToUint32(num: number) {
530
+        const uint32 = new Uint32Array(1);
531
+        uint32[0] = num;
532
+        return uint32[0];
533
+    }
534
+
539
     /**
535
     /**
540
      * mute specified remote video stream.
536
      * mute specified remote video stream.
541
      *
537
      *