AgoraIO-Community / Agora-RTC-React

A react wrapper for Agora RTC NG SDK
MIT License
92 stars 48 forks source link

Export the AgoraRTCErrorCode enum instead of just the declaration #24

Closed pcardune closed 2 years ago

pcardune commented 2 years ago

Previously when using this library from typescript, importing AgoraRTCErrorCode would pass type checks even though nothing was actually exported, causing an undefined exception at run time.

For example:

import { AgoraRTCErrorCode, createMicrophoneAndCameraTracks } from 'agora-rtc-react';

try {
  createMicrophoneAndCameraTracks()
} catch (e) {
  if (e.code === AgoraRTCErrorCode.PERMISSION_DENIED) {
                                     // ^--- throws exception because AgoraRTCErrorCode is undefined
    console.log("User did not give camera/mic permissions");
  } else {
    throw e;
  }
}

After this PR, the code example will work without an exception being thrown.

EkaanshArora commented 2 years ago

Thanks for the PR, I'll do a quick check later today and merge!

EkaanshArora commented 2 years ago

Thanks again :)