podchat-browser
Version:
Javascript SDK to use POD's Chat Service - Browser Only
225 lines (199 loc) • 7.39 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _constants = require("../../constants");
var _errorHandler = require("../../errorHandler");
function AdminMethods(app) {
var publicized = {
restrictCallSession: function restrictCallSession(params) {
var call = app.call.currentCall();
if (!call) {
app.errorHandler.raiseError(_errorHandler.errorList.INVALID_CALLID, null, true, {});
return;
}
var sendDataContent = {};
if (params) {
if (typeof +params.callId === 'number' && params.callId > 0) {
sendDataContent.callId = +params.callId;
} else {
app.errorHandler.raiseError(_errorHandler.errorList.INVALID_CALLID, null, true, {});
return;
}
if (typeof params.state === 'boolean') {
sendDataContent.state = params.state;
} else {
app.chatEvents.fireEvent('error', {
code: 999,
message: '[SDK] parameter state is not valid. expected value: true|false'
});
return;
}
} else {
app.chatEvents.fireEvent('error', {
code: 999,
message: '[SDK] No params have been sent to restrictCallSession'
});
return;
}
var sendData = {
chatMessageVOType: _constants.chatMessageVOTypes.RESTRICT_CALL_SESSION,
typeCode: params.typeCode,
pushMsgType: 3,
subjectId: sendDataContent.callId,
token: app.sdkParams.token,
content: {
restricted: sendDataContent.state
}
};
return app.messenger.sendMessage(sendData);
},
addCallParticipantsPermission: function addCallParticipantsPermission(params) {
var call = app.call.currentCall();
if (!call) {
app.errorHandler.raiseError(_errorHandler.errorList.INVALID_CALLID, null, true, {});
return;
}
var sendDataContent = {};
if (params) {
if (typeof +params.callId === 'number' && params.callId > 0) {
sendDataContent.callId = +params.callId;
} else {
app.errorHandler.raiseError(_errorHandler.errorList.INVALID_CALLID, null, true, {});
return;
}
if (Array.isArray(params.invitees) && params.invitees.length) {
sendDataContent.invitees = []; //params.invitees;
for (var i = 0; i < params.invitees.length; i++) {
var tempInvitee = params.invitees[i];
if (tempInvitee && typeof tempInvitee.idType === "string") {
tempInvitee.idType = _constants.inviteeVOidTypes[tempInvitee.idType];
sendDataContent.invitees.push(tempInvitee);
} else if (tempInvitee) {
sendDataContent.invitees.push(tempInvitee);
}
}
} else {
app.chatEvents.fireEvent('error', {
code: 999,
message: '[SDK] invitees list is empty.'
});
return;
}
if (Array.isArray(params.allowedCallActions) && params.allowedCallActions.length) {
sendDataContent.allowedCallActions = params.allowedCallActions;
} else {
app.chatEvents.fireEvent('error', {
code: 999,
message: '[SDK] allowedCallActions list is empty.'
});
return;
}
} else {
app.chatEvents.fireEvent('error', {
code: 999,
message: '[SDK] No params have been sent to addCallParticipantsPermission'
});
return;
}
var sendData = {
chatMessageVOType: _constants.chatMessageVOTypes.SET_PERMISSION_TO_CALL_PARTICIPANT,
typeCode: params.typeCode,
pushMsgType: 3,
subjectId: sendDataContent.callId,
content: sendDataContent,
token: app.sdkParams.token
};
return app.messenger.sendMessage(sendData);
},
removeCallParticipantsPermission: function removeCallParticipantsPermission(params) {
var call = app.call.currentCall();
if (!call) {
app.errorHandler.raiseError(_errorHandler.errorList.INVALID_CALLID, null, true, {});
return;
}
var sendDataContent = {};
if (params) {
if (typeof +params.callId === 'number' && params.callId > 0) {
sendDataContent.callId = +params.callId;
} else {
app.errorHandler.raiseError(_errorHandler.errorList.INVALID_CALLID, null, true, {});
return;
}
if (Array.isArray(params.invitees) && params.invitees.length) {
sendDataContent.invitees = []; //params.invitees;
for (var i = 0; i < params.invitees.length; i++) {
var tempInvitee = params.invitees[i];
if (tempInvitee && typeof tempInvitee.idType === "string") {
tempInvitee.idType = _constants.inviteeVOidTypes[tempInvitee.idType];
sendDataContent.invitees.push(tempInvitee);
} else if (tempInvitee) {
sendDataContent.invitees.push(tempInvitee);
}
}
} else {
app.chatEvents.fireEvent('error', {
code: 999,
message: '[SDK] invitees list is empty.'
});
return;
}
if (Array.isArray(params.allowedCallActions) && params.allowedCallActions.length) {
sendDataContent.allowedCallActions = params.allowedCallActions;
} else {
app.chatEvents.fireEvent('error', {
code: 999,
message: '[SDK] allowedCallActions list is empty.'
});
return;
}
} else {
app.chatEvents.fireEvent('error', {
code: 999,
message: '[SDK] No params have been sent to removeCallParticipantsPermission'
});
return;
}
var sendData = {
chatMessageVOType: _constants.chatMessageVOTypes.REMOVE_PERMISSION_FROM_CALL_PARTICIPANT,
typeCode: params.typeCode,
pushMsgType: 3,
subjectId: sendDataContent.callId,
token: app.sdkParams.token,
content: sendDataContent
};
return app.messenger.sendMessage(sendData);
},
onRestrictCallSession: function onRestrictCallSession(uniqueId, messageContent, chatMessage, threadId) {
app.chatEvents.fireEvent('callEvents', {
type: 'RESTRICT_CALL_ACTIONS',
typeCode: chatMessage.typeCode,
callId: threadId,
result: messageContent,
uniqueId: uniqueId
});
},
onAddCallParticipantsPermission: function onAddCallParticipantsPermission(uniqueId, messageContent, chatMessage, threadId) {
app.chatEvents.fireEvent('callEvents', {
type: 'ADD_CALL_PARTICIPANTS_PERMISSION',
typeCode: chatMessage.typeCode,
callId: threadId,
result: messageContent,
uniqueId: uniqueId
});
},
onRemoveCallParticipantsPermission: function onRemoveCallParticipantsPermission(uniqueId, messageContent, chatMessage, threadId) {
app.chatEvents.fireEvent('callEvents', {
type: 'REMOVE_CALL_PARTICIPANTS_PERMISSION',
typeCode: chatMessage.typeCode,
callId: threadId,
result: messageContent,
uniqueId: uniqueId
});
}
};
return publicized;
}
var _default = AdminMethods;
exports["default"] = _default;