UNPKG

agora-react-native-rtm

Version:

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

114 lines 6.08 kB
import { RTMPresence } from '../api/RTMPresence'; import { PresenceOptions } from '../legacy/AgoraRtmBase'; import { IRtmPresenceImpl } from '../legacy/impl/IAgoraRtmPresenceImpl'; import { handleError, wrapRtmResult } from './IrisRtmEngine'; export class RtmPresenceInternal extends RTMPresence { _rtmPresenceImpl = new IRtmPresenceImpl(); async whoNow(channelName, channelType, options) { let operation = 'whoNow'; let callBack = 'onWhoNowResult'; try { var _result$callBackResul, _result$callBackResul2, _result$callBackResul3; const status = this._rtmPresenceImpl.whoNow(channelName, channelType, options ? options : new PresenceOptions()); let result = await wrapRtmResult(status, operation, callBack, true); return { timestamp: result.timestamp, totalOccupancy: (_result$callBackResul = result.callBackResult) === null || _result$callBackResul === void 0 ? void 0 : _result$callBackResul.count, occupants: (_result$callBackResul2 = result.callBackResult) === null || _result$callBackResul2 === void 0 ? void 0 : _result$callBackResul2.userStateList, nextPage: (_result$callBackResul3 = result.callBackResult) === null || _result$callBackResul3 === void 0 ? void 0 : _result$callBackResul3.nextPage }; } catch (error) { throw handleError(error, operation); } } async getOnlineUsers(channelName, channelType, options) { let operation = 'getOnlineUsers'; let callBack = 'onGetOnlineUsersResult'; try { var _result$callBackResul4, _result$callBackResul5, _result$callBackResul6; const status = this._rtmPresenceImpl.getOnlineUsers(channelName, channelType, options ? options : new PresenceOptions()); let result = await wrapRtmResult(status, operation, callBack, true); return { timestamp: result.timestamp, totalOccupancy: (_result$callBackResul4 = result.callBackResult) === null || _result$callBackResul4 === void 0 ? void 0 : _result$callBackResul4.count, occupants: (_result$callBackResul5 = result.callBackResult) === null || _result$callBackResul5 === void 0 ? void 0 : _result$callBackResul5.userStateList, nextPage: (_result$callBackResul6 = result.callBackResult) === null || _result$callBackResul6 === void 0 ? void 0 : _result$callBackResul6.nextPage }; } catch (error) { throw handleError(error, operation); } } async whereNow(userId) { let operation = 'whereNow'; let callBack = 'onWhereNowResult'; try { var _result$callBackResul7, _result$callBackResul8; const status = this._rtmPresenceImpl.whereNow(userId); let result = await wrapRtmResult(status, operation, callBack, true); return { timestamp: result.timestamp, channels: (_result$callBackResul7 = result.callBackResult) === null || _result$callBackResul7 === void 0 ? void 0 : _result$callBackResul7.channels, totalChannel: (_result$callBackResul8 = result.callBackResult) === null || _result$callBackResul8 === void 0 ? void 0 : _result$callBackResul8.count }; } catch (error) { throw handleError(error, operation); } } async getUserChannels(userId) { let operation = 'getUserChannels'; let callBack = 'onGetUserChannelsResult'; try { var _result$callBackResul9, _result$callBackResul10; const status = this._rtmPresenceImpl.getUserChannels(userId); let result = await wrapRtmResult(status, operation, callBack, true); return { timestamp: result.timestamp, channels: (_result$callBackResul9 = result.callBackResult) === null || _result$callBackResul9 === void 0 ? void 0 : _result$callBackResul9.channels, totalChannel: (_result$callBackResul10 = result.callBackResult) === null || _result$callBackResul10 === void 0 ? void 0 : _result$callBackResul10.count }; } catch (error) { throw handleError(error, operation); } } async setState(channelName, channelType, state) { let operation = 'setState'; let callBack = 'onPresenceSetStateResult'; try { const status = this._rtmPresenceImpl.setState(channelName, channelType, [state], 1); let result = await wrapRtmResult(status, operation, callBack, true); return result; } catch (error) { throw handleError(error, operation); } } async getState(userId, channelName, channelType) { let operation = 'getState'; let callBack = 'onPresenceGetStateResult'; try { var _result$callBackResul11, _result$callBackResul12, _result$callBackResul13; const status = this._rtmPresenceImpl.getState(channelName, channelType, userId); let result = await wrapRtmResult(status, operation, callBack, true); return { timestamp: result.timestamp, statesCount: (_result$callBackResul11 = result.callBackResult) === null || _result$callBackResul11 === void 0 ? void 0 : _result$callBackResul11.state.statesCount, states: (_result$callBackResul12 = result.callBackResult) === null || _result$callBackResul12 === void 0 ? void 0 : _result$callBackResul12.state.states, userId: (_result$callBackResul13 = result.callBackResult) === null || _result$callBackResul13 === void 0 ? void 0 : _result$callBackResul13.state.userId }; } catch (error) { throw handleError(error, operation); } } async removeState(channelName, channelType, options) { let operation = 'removeState'; let callBack = 'onPresenceRemoveStateResult'; try { var _options$states; const status = this._rtmPresenceImpl.removeState(channelName, channelType, (options === null || options === void 0 ? void 0 : options.states) ?? [], (options === null || options === void 0 || (_options$states = options.states) === null || _options$states === void 0 ? void 0 : _options$states.length) ?? 0); let result = await wrapRtmResult(status, operation, callBack, true); return result; } catch (error) { throw handleError(error, operation); } } } //# sourceMappingURL=RtmPresenceInternal.js.map