UNPKG

podchat-browser

Version:

Javascript SDK to use POD's Chat Service - Browser Only

218 lines (193 loc) 8.64 kB
import {chatMessageVOTypes, inviteeVOidTypes} from "../../constants"; import {errorList} from "../../errorHandler"; function AdminMethods(app) { let publicized = { restrictCallSession(params) { let call = app.call.currentCall(); if (!call) { app.errorHandler.raiseError(errorList.INVALID_CALLID, null, true, {}); return; } let sendDataContent = {}; if (params) { if (typeof +params.callId === 'number' && params.callId > 0) { sendDataContent.callId = +params.callId; } else { app.errorHandler.raiseError(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; } let sendData = { chatMessageVOType: 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(params) { let call = app.call.currentCall(); if (!call) { app.errorHandler.raiseError(errorList.INVALID_CALLID, null, true, {}); return; } let sendDataContent = {}; if (params) { if (typeof +params.callId === 'number' && params.callId > 0) { sendDataContent.callId = +params.callId; } else { app.errorHandler.raiseError(errorList.INVALID_CALLID, null, true, {}); return; } if (Array.isArray(params.invitees) && params.invitees.length) { sendDataContent.invitees = [];//params.invitees; for (let i = 0; i < params.invitees.length; i++) { let tempInvitee = params.invitees[i]; if (tempInvitee && typeof tempInvitee.idType === "string") { tempInvitee.idType = 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; } let sendData = { chatMessageVOType: 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(params) { let call = app.call.currentCall(); if (!call) { app.errorHandler.raiseError(errorList.INVALID_CALLID, null, true, {}); return; } let sendDataContent = {}; if (params) { if (typeof +params.callId === 'number' && params.callId > 0) { sendDataContent.callId = +params.callId; } else { app.errorHandler.raiseError(errorList.INVALID_CALLID, null, true, {}); return; } if (Array.isArray(params.invitees) && params.invitees.length) { sendDataContent.invitees = [];//params.invitees; for (let i = 0; i < params.invitees.length; i++) { let tempInvitee = params.invitees[i]; if (tempInvitee && typeof tempInvitee.idType === "string") { tempInvitee.idType = 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; } let sendData = { chatMessageVOType: 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(uniqueId, messageContent, chatMessage, threadId){ app.chatEvents.fireEvent('callEvents', { type: 'RESTRICT_CALL_ACTIONS', typeCode: chatMessage.typeCode, callId: threadId, result: messageContent, uniqueId }); }, onAddCallParticipantsPermission(uniqueId, messageContent, chatMessage, threadId){ app.chatEvents.fireEvent('callEvents', { type: 'ADD_CALL_PARTICIPANTS_PERMISSION', typeCode: chatMessage.typeCode, callId: threadId, result: messageContent, uniqueId }); }, onRemoveCallParticipantsPermission(uniqueId, messageContent, chatMessage, threadId){ app.chatEvents.fireEvent('callEvents', { type: 'REMOVE_CALL_PARTICIPANTS_PERMISSION', typeCode: chatMessage.typeCode, callId: threadId, result: messageContent, uniqueId }); } }; return publicized; } export default AdminMethods;