agora-react-native-rtm
Version:
React Native around the Agora RTM SDKs for Android and iOS agora
187 lines • 11.2 kB
JavaScript
import { RTMStorage } from '../api/RTMStorage';
import { Metadata } from '../legacy/IAgoraRtmStorage';
import { MetadataOptions } from '../legacy/IAgoraRtmStorage';
import { IRtmStorageImpl } from '../legacy/impl/IAgoraRtmStorageImpl';
import { handleError, wrapRtmResult } from './IrisRtmEngine';
export class RtmStorageInternal extends RTMStorage {
_rtmStorageImpl = new IRtmStorageImpl();
async setChannelMetadata(channelName, channelType, data, options) {
let operation = 'setChannelMetadata';
let callBack = 'onSetChannelMetadataResult';
try {
var _result$callBackResul, _result$callBackResul2;
const status = this._rtmStorageImpl.setChannelMetadata(channelName, channelType, data, new MetadataOptions({
recordTs: options === null || options === void 0 ? void 0 : options.addTimeStamp,
recordUserId: options === null || options === void 0 ? void 0 : options.addUserId
}), (options === null || options === void 0 ? void 0 : options.lockName) ?? '');
let result = await wrapRtmResult(status, operation, callBack, true);
return {
timestamp: result.timestamp,
channelName: (_result$callBackResul = result.callBackResult) === null || _result$callBackResul === void 0 ? void 0 : _result$callBackResul.channelName,
channelType: (_result$callBackResul2 = result.callBackResult) === null || _result$callBackResul2 === void 0 ? void 0 : _result$callBackResul2.channelType
};
} catch (error) {
throw handleError(error, operation);
}
}
async getChannelMetadata(channelName, channelType) {
let operation = 'getChannelMetadata';
let callBack = 'onGetChannelMetadataResult';
try {
var _result$callBackResul3, _result$callBackResul4, _result$callBackResul5, _result$callBackResul6, _result$callBackResul7;
const status = this._rtmStorageImpl.getChannelMetadata(channelName, channelType);
let result = await wrapRtmResult(status, operation, callBack, true);
return {
timestamp: result.timestamp,
channelName: (_result$callBackResul3 = result.callBackResult) === null || _result$callBackResul3 === void 0 ? void 0 : _result$callBackResul3.channelName,
channelType: (_result$callBackResul4 = result.callBackResult) === null || _result$callBackResul4 === void 0 ? void 0 : _result$callBackResul4.channelType,
majorRevision: (_result$callBackResul5 = result.callBackResult) === null || _result$callBackResul5 === void 0 || (_result$callBackResul5 = _result$callBackResul5.data) === null || _result$callBackResul5 === void 0 ? void 0 : _result$callBackResul5.majorRevision,
items: (_result$callBackResul6 = result.callBackResult) === null || _result$callBackResul6 === void 0 || (_result$callBackResul6 = _result$callBackResul6.data) === null || _result$callBackResul6 === void 0 ? void 0 : _result$callBackResul6.items,
itemCount: (_result$callBackResul7 = result.callBackResult) === null || _result$callBackResul7 === void 0 || (_result$callBackResul7 = _result$callBackResul7.data) === null || _result$callBackResul7 === void 0 ? void 0 : _result$callBackResul7.itemCount
};
} catch (error) {
throw handleError(error, operation);
}
}
async removeChannelMetadata(channelName, channelType, options) {
let operation = 'removeChannelMetadata';
let callBack = 'onRemoveChannelMetadataResult';
try {
var _result$callBackResul8, _result$callBackResul9;
const status = this._rtmStorageImpl.removeChannelMetadata(channelName, channelType, (options === null || options === void 0 ? void 0 : options.data) ?? new Metadata(), new MetadataOptions({
recordTs: options === null || options === void 0 ? void 0 : options.addTimeStamp,
recordUserId: options === null || options === void 0 ? void 0 : options.addUserId
}), (options === null || options === void 0 ? void 0 : options.lockName) ?? '');
let result = await wrapRtmResult(status, operation, callBack, true);
return {
timestamp: result.timestamp,
channelName: (_result$callBackResul8 = result.callBackResult) === null || _result$callBackResul8 === void 0 ? void 0 : _result$callBackResul8.channelName,
channelType: (_result$callBackResul9 = result.callBackResult) === null || _result$callBackResul9 === void 0 ? void 0 : _result$callBackResul9.channelType
};
} catch (error) {
throw handleError(error, operation);
}
}
async updateChannelMetadata(channelName, channelType, data, options) {
let operation = 'updateChannelMetadata';
let callBack = 'onUpdateChannelMetadataResult';
try {
var _result$callBackResul10, _result$callBackResul11;
const status = this._rtmStorageImpl.updateChannelMetadata(channelName, channelType, data, new MetadataOptions({
recordTs: options === null || options === void 0 ? void 0 : options.addTimeStamp,
recordUserId: options === null || options === void 0 ? void 0 : options.addUserId
}), (options === null || options === void 0 ? void 0 : options.lockName) ?? '');
let result = await wrapRtmResult(status, operation, callBack, true);
return {
timestamp: result.timestamp,
channelName: (_result$callBackResul10 = result.callBackResult) === null || _result$callBackResul10 === void 0 ? void 0 : _result$callBackResul10.channelName,
channelType: (_result$callBackResul11 = result.callBackResult) === null || _result$callBackResul11 === void 0 ? void 0 : _result$callBackResul11.channelType
};
} catch (error) {
throw handleError(error, operation);
}
}
async setUserMetadata(data, options) {
let operation = 'setUserMetadata';
let callBack = 'onSetUserMetadataResult';
try {
var _result$callBackResul12;
const status = this._rtmStorageImpl.setUserMetadata((options === null || options === void 0 ? void 0 : options.userId) ?? '', data, new MetadataOptions({
recordTs: options === null || options === void 0 ? void 0 : options.addTimeStamp,
recordUserId: options === null || options === void 0 ? void 0 : options.addUserId
}));
let result = await wrapRtmResult(status, operation, callBack, true);
return {
timestamp: result.timestamp,
userId: (_result$callBackResul12 = result.callBackResult) === null || _result$callBackResul12 === void 0 ? void 0 : _result$callBackResul12.userId
};
} catch (error) {
throw handleError(error, operation);
}
}
async getUserMetadata(options) {
let operation = 'getUserMetadata';
let callBack = 'onGetUserMetadataResult';
try {
var _result$callBackResul13, _result$callBackResul14, _result$callBackResul15, _result$callBackResul16;
const status = this._rtmStorageImpl.getUserMetadata((options === null || options === void 0 ? void 0 : options.userId) ?? '');
let result = await wrapRtmResult(status, operation, callBack, true);
return {
timestamp: result.timestamp,
userId: (_result$callBackResul13 = result.callBackResult) === null || _result$callBackResul13 === void 0 ? void 0 : _result$callBackResul13.userId,
majorRevision: (_result$callBackResul14 = result.callBackResult) === null || _result$callBackResul14 === void 0 || (_result$callBackResul14 = _result$callBackResul14.data) === null || _result$callBackResul14 === void 0 ? void 0 : _result$callBackResul14.majorRevision,
items: (_result$callBackResul15 = result.callBackResult) === null || _result$callBackResul15 === void 0 || (_result$callBackResul15 = _result$callBackResul15.data) === null || _result$callBackResul15 === void 0 ? void 0 : _result$callBackResul15.items,
itemCount: (_result$callBackResul16 = result.callBackResult) === null || _result$callBackResul16 === void 0 || (_result$callBackResul16 = _result$callBackResul16.data) === null || _result$callBackResul16 === void 0 ? void 0 : _result$callBackResul16.itemCount
};
} catch (error) {
throw handleError(error, operation);
}
}
async updateUserMetadata(data, options) {
let operation = 'updateUserMetadata';
let callBack = 'onUpdateUserMetadataResult';
try {
var _result$callBackResul17;
const status = this._rtmStorageImpl.updateUserMetadata((options === null || options === void 0 ? void 0 : options.userId) ?? '', data, new MetadataOptions({
recordTs: options === null || options === void 0 ? void 0 : options.addTimeStamp,
recordUserId: options === null || options === void 0 ? void 0 : options.addUserId
}));
let result = await wrapRtmResult(status, operation, callBack, true);
return {
timestamp: result.timestamp,
userId: (_result$callBackResul17 = result.callBackResult) === null || _result$callBackResul17 === void 0 ? void 0 : _result$callBackResul17.userId
};
} catch (error) {
throw handleError(error, operation);
}
}
async subscribeUserMetadata(userId) {
let operation = 'subscribeUserMetadata';
let callBack = 'onSubscribeUserMetadataResult';
try {
var _result$callBackResul18;
const status = this._rtmStorageImpl.subscribeUserMetadata(userId);
let result = await wrapRtmResult(status, operation, callBack, true);
return {
timestamp: result.timestamp,
userId: (_result$callBackResul18 = result.callBackResult) === null || _result$callBackResul18 === void 0 ? void 0 : _result$callBackResul18.userId
};
} catch (error) {
throw handleError(error, operation);
}
}
async unsubscribeUserMetadata(userId) {
let operation = 'unsubscribeUserMetadata';
let callBack = 'onUnsubscribeUserMetadataResult';
try {
var _result$callBackResul19;
const status = this._rtmStorageImpl.unsubscribeUserMetadata(userId);
let result = await wrapRtmResult(status, operation, callBack, true);
return {
timestamp: result.timestamp,
userId: (_result$callBackResul19 = result.callBackResult) === null || _result$callBackResul19 === void 0 ? void 0 : _result$callBackResul19.userId
};
} catch (error) {
throw handleError(error, operation);
}
}
async removeUserMetadata(options) {
let operation = 'removeUserMetadata';
let callBack = 'onRemoveUserMetadataResult';
try {
var _result$callBackResul20;
const status = this._rtmStorageImpl.removeUserMetadata((options === null || options === void 0 ? void 0 : options.userId) ?? '', (options === null || options === void 0 ? void 0 : options.data) ?? new Metadata(), new MetadataOptions({
recordTs: options === null || options === void 0 ? void 0 : options.addTimeStamp,
recordUserId: options === null || options === void 0 ? void 0 : options.addUserId
}));
let result = await wrapRtmResult(status, operation, callBack, true);
return {
timestamp: result.timestamp,
userId: (_result$callBackResul20 = result.callBackResult) === null || _result$callBackResul20 === void 0 ? void 0 : _result$callBackResul20.userId
};
} catch (error) {
throw handleError(error, operation);
}
}
}
//# sourceMappingURL=RtmStorageInternal.js.map