UNPKG

agora-react-native-rtm

Version:

React Native around the Agora RTM SDKs for Android and iOS agora

126 lines 4.35 kB
import { TopicMessageOptions } from '../legacy/AgoraRtmBase'; import { JoinTopicOptions, TopicOptions } from '../legacy/IAgoraStreamChannel'; import { IStreamChannelImpl } from '../legacy/impl/IAgoraStreamChannelImpl'; import { handleError, wrapRtmResult } from './IrisRtmEngine'; export class StreamChannelInternal extends IStreamChannelImpl { _channelName = ''; constructor(channelName) { super(); console.log('create streamChannel', channelName); this._channelName = channelName; } get channelName() { return this._channelName; } join(options) { let operation = 'join'; let callBack = 'onJoinResult'; try { const status = super.join(options); return wrapRtmResult(status, operation, callBack); } catch (error) { throw handleError(error, operation); } } leave() { let operation = 'leave'; let callBack = 'onLeaveResult'; try { const status = super.leave(); return wrapRtmResult(status, operation, callBack); } catch (error) { throw handleError(error, operation); } } async joinTopic(topicName, options) { let operation = 'joinTopic'; let callBack = 'onJoinTopicResult'; try { const status = super.joinTopic(topicName, options ? options : new JoinTopicOptions()); let result = await wrapRtmResult(status, operation, callBack); return { ...result, topicName }; } catch (error) { throw handleError(error, operation); } } async publishTopicMessage(topicName, message, options) { let operation = 'publishTopicMessage'; let callBack = 'onPublishTopicMessageResult'; try { const status = super.publishTopicMessage(topicName, message, options ? options : new TopicMessageOptions()); let result = await wrapRtmResult(status, operation, callBack); return { ...result, topicName }; } catch (error) { throw handleError(error, operation); } } async leaveTopic(topicName) { let operation = 'leaveTopic'; let callBack = 'onLeaveTopicResult'; try { const status = super.leaveTopic(topicName); let result = await wrapRtmResult(status, operation, callBack); return { ...result, topicName }; } catch (error) { throw handleError(error, operation); } } async subscribeTopic(topicName, options) { let operation = 'subscribeTopic'; let callBack = 'onSubscribeTopicResult'; try { var _result$callBackResul, _result$callBackResul2; const status = super.subscribeTopic(topicName, options ? options : new TopicOptions()); let result = await wrapRtmResult(status, operation, callBack, true); return { succeedUsers: (_result$callBackResul = result.callBackResult) === null || _result$callBackResul === void 0 ? void 0 : _result$callBackResul.succeedUsers, failedUsers: (_result$callBackResul2 = result.callBackResult) === null || _result$callBackResul2 === void 0 ? void 0 : _result$callBackResul2.failedUsers, timestamp: result.timestamp, topicName }; } catch (error) { throw handleError(error, operation); } } async unsubscribeTopic(topicName, options) { let operation = 'unsubscribeTopic'; let callBack = 'onUnsubscribeTopicResult'; try { const status = super.unsubscribeTopic(topicName, options ? options : new TopicOptions()); let result = await wrapRtmResult(status, operation, callBack); return result; } catch (error) { throw handleError(error, operation); } } async getSubscribedUserList(topicName) { let operation = 'getSubscribedUserList'; let callBack = 'onGetSubscribedUserListResult'; try { var _result$callBackResul3; const status = super.getSubscribedUserList(topicName, 0); let result = await wrapRtmResult(status, operation, callBack, true); return { subscribed: (_result$callBackResul3 = result.callBackResult) === null || _result$callBackResul3 === void 0 ? void 0 : _result$callBackResul3.users, topicName, timestamp: result.timestamp }; } catch (error) { throw handleError(error, operation); } } release() { const ret = super.release(); return ret; } } //# sourceMappingURL=StreamChannelInternal.js.map