UNPKG

agora-react-native-rtm

Version:

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

121 lines (120 loc) 6.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RtmPresenceInternal = void 0; var _RTMPresence = require("../api/RTMPresence"); var _AgoraRtmBase = require("../legacy/AgoraRtmBase"); var _IAgoraRtmPresenceImpl = require("../legacy/impl/IAgoraRtmPresenceImpl"); var _IrisRtmEngine = require("./IrisRtmEngine"); class RtmPresenceInternal extends _RTMPresence.RTMPresence { _rtmPresenceImpl = new _IAgoraRtmPresenceImpl.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 _AgoraRtmBase.PresenceOptions()); let result = await (0, _IrisRtmEngine.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 (0, _IrisRtmEngine.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 _AgoraRtmBase.PresenceOptions()); let result = await (0, _IrisRtmEngine.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 (0, _IrisRtmEngine.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 (0, _IrisRtmEngine.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 (0, _IrisRtmEngine.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 (0, _IrisRtmEngine.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 (0, _IrisRtmEngine.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 (0, _IrisRtmEngine.wrapRtmResult)(status, operation, callBack, true); return result; } catch (error) { throw (0, _IrisRtmEngine.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 (0, _IrisRtmEngine.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 (0, _IrisRtmEngine.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 (0, _IrisRtmEngine.wrapRtmResult)(status, operation, callBack, true); return result; } catch (error) { throw (0, _IrisRtmEngine.handleError)(error, operation); } } } exports.RtmPresenceInternal = RtmPresenceInternal; //# sourceMappingURL=RtmPresenceInternal.js.map