//
//  JYWhiteBoardModule.m
//  react-native-white-board
//
//  Created by yrx on 2021/3/18.
//

#import "JYWhiteBoardModule.h"
#import "JYWhiteBoardManager.h"

@implementation JYWhiteBoardModule
RCT_EXPORT_MODULE();
+ (BOOL)requiresMainQueueSetup
{
  return YES;
}
- (NSArray<NSString *> *)supportedEvents
{
  return @[@"onRoomStateChanged"];
}

RCT_EXPORT_METHOD(init:(NSDictionary *)options resolver:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject)
{
    @try {
        [[JYWhiteBoardManager shareManager] initWithOptions:options whiteBoardModule:self];
        resolve([NSNumber numberWithBool:YES]);
    } @catch (NSException *exception) {
        reject([exception name],[exception reason],NULL);
    }
}
RCT_EXPORT_METHOD(joinRoom:(NSDictionary *)options resolver:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject)
{
    @try {
        [[JYWhiteBoardManager shareManager] joinRoomWithOptions:options];
        resolve([NSNumber numberWithBool:YES]);
    } @catch (NSException *exception) {
        reject([exception name],[exception reason],NULL);
    }
}
RCT_EXPORT_METHOD(destroy:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject)
{
    @try {
        [[JYWhiteBoardManager shareManager] destroy];
        resolve([NSNumber numberWithBool:YES]);
    } @catch (NSException *exception) {
        reject([exception name],[exception reason],NULL);
    }
}
@end
