AgoraIO-Extensions / react-native-agora

React Native around the Agora RTC SDKs for Android and iOS agora
https://www.agora.io
MIT License
625 stars 227 forks source link

Inconsistency between TypeScript definition and implementation for uid parameter in joinChannel method #830

Open scozdev opened 2 days ago

scozdev commented 2 days ago

Describe the bug The joinChannel method in the IAgoraRtcEngine interface expects the uid parameter to be a number, but the TypeScript definition allows it to be a string. This inconsistency leads to a -2 error (invalid parameter) when a string UID is provided, even though the type definition suggests it should be valid.

To Reproduce Steps to reproduce the behavior:

  1. Initialize the Agora RTC engine
  2. Attempt to join a channel using a string UID
  3. Observe that the joinChannel method returns -2 (invalid parameter)

Expected behavior The joinChannel method should either:

  1. Accept both number and string types for the uid parameter, as implied by the current TypeScript definition, or
  2. The TypeScript definition should be updated to only allow number types for the uid parameter to match the actual implementation.

Code example

import RtcEngine from 'react-native-agora';
// ...
const joinChannel = async () => {
  if (engine && roomID && token) {
    try {
    // This causes a -2 error, even though the type definition allows string
    const result = await engine.joinChannel(token, roomID, "user123", null);
    console.log('Join channel result:', result);
    } catch (error) {
    console.error('Failed to join channel:', error);
    }
  }
};

Environment:

Additional context The TypeScript definition in node_modules/react-native-agora/src/IAgoraRtcEngine.ts shows:

abstract joinChannel(
token: string,
channelId: string,
uid: number | string, // Note: allows both number and string
options: ChannelMediaOptions
): number;

However, the actual implementation only accepts a number for the uid parameter. This discrepancy between the type definition and the implementation is causing confusion and potential runtime errors.

Proposed solution Either update the implementation to accept both number and string types for uid, or update the TypeScript definition to only allow number types. This will ensure consistency between the type definition and the actual behavior of the method.

guoxianzhe commented 2 days ago

@scozdev If you want to use string uid to joinchannel, you can use joinChannelWithUserAccount