
#import "DataChannelWrapper.h"

#import <DyteWebRTC/RTCDataChannel.h>

@interface DataChannelWrapper ()<DyteRTCDataChannelDelegate>
@end

@implementation DataChannelWrapper

- (instancetype)initWithChannel:(DyteRTCDataChannel *)channel reactTag:(NSString *)tag {
    self = [super init];
    if (self) {
        _channel = channel;
        _reactTag = tag;

        // Set ourselves as the deletagate.
        _channel.delegate = self;
    }

    return self;
}

- (void)dataChannel:(nonnull DyteRTCDataChannel *)dataChannel didReceiveMessageWithBuffer:(nonnull DyteRTCDataBuffer *)buffer {
    if (_delegate) {
        [_delegate dataChannel:self didReceiveMessageWithBuffer:buffer];
    }
}

- (void)dataChannelDidChangeState:(nonnull DyteRTCDataChannel *)dataChannel {
    if (_delegate) {
        [_delegate dataChannelDidChangeState:self];
    }
}

- (void)dataChannel:(nonnull DyteRTCDataChannel *)dataChannel didChangeBufferedAmount:(uint64_t)amount {
    if (_delegate) {
        [_delegate dataChannel:self didChangeBufferedAmount:amount];
    }
}

@end
