pubnub
Version:
Publish & Subscribe Real-time Messaging with PubNub
80 lines (63 loc) • 2.57 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getOperation = getOperation;
exports.validateParams = validateParams;
exports.getURL = getURL;
exports.getRequestTimeout = getRequestTimeout;
exports.isAuthSupported = isAuthSupported;
exports.prepareParams = prepareParams;
exports.handleResponse = handleResponse;
var _flow_interfaces = require("../../flow_interfaces");
var _operations = _interopRequireDefault(require("../../constants/operations"));
var _utils = _interopRequireDefault(require("../../utils"));
function getOperation() {
return _operations["default"].PNGetStateOperation;
}
function validateParams(modules) {
var config = modules.config;
if (!config.subscribeKey) return 'Missing Subscribe Key';
}
function getURL(modules, incomingParams) {
var config = modules.config;
var _incomingParams$uuid = incomingParams.uuid,
uuid = _incomingParams$uuid === void 0 ? config.UUID : _incomingParams$uuid,
_incomingParams$chann = incomingParams.channels,
channels = _incomingParams$chann === void 0 ? [] : _incomingParams$chann;
var stringifiedChannels = channels.length > 0 ? channels.join(',') : ',';
return "/v2/presence/sub-key/".concat(config.subscribeKey, "/channel/").concat(_utils["default"].encodeString(stringifiedChannels), "/uuid/").concat(uuid);
}
function getRequestTimeout(_ref) {
var config = _ref.config;
return config.getTransactionTimeout();
}
function isAuthSupported() {
return true;
}
function prepareParams(modules, incomingParams) {
var _incomingParams$chann2 = incomingParams.channelGroups,
channelGroups = _incomingParams$chann2 === void 0 ? [] : _incomingParams$chann2;
var params = {};
if (channelGroups.length > 0) {
params['channel-group'] = channelGroups.join(',');
}
return params;
}
function handleResponse(modules, serverResponse, incomingParams) {
var _incomingParams$chann3 = incomingParams.channels,
channels = _incomingParams$chann3 === void 0 ? [] : _incomingParams$chann3,
_incomingParams$chann4 = incomingParams.channelGroups,
channelGroups = _incomingParams$chann4 === void 0 ? [] : _incomingParams$chann4;
var channelsResponse = {};
if (channels.length === 1 && channelGroups.length === 0) {
channelsResponse[channels[0]] = serverResponse.payload;
} else {
channelsResponse = serverResponse.payload;
}
return {
channels: channelsResponse
};
}
//# sourceMappingURL=get_state.js.map