@photocurio Thanks. How did you manage the ACS objects like call agents. Let me share the code which i am trying to do via Store. I am trying to store callAgent in the state but when i am accessing i am not able to get methods from the state.
How and where do you have callAgent in app. @photocurio
import { createStore } from 'vuex';
import { CallClient, LocalVideoStream, Renderer } from '@azure/communication-calling';
import { AzureCommunicationTokenCredential } from '@azure/communication-common';
/* eslint-disable */
export default createStore({
state: {
meetingLinkInput: 'link',
callAgent: {},
deviceManager: {},
outgoing: {
userToCall: '',
canCall: false,
canHangUp: false,
},
incoming: {
callerId: '',
canAccept: true,
canDecline: false,
},
call: {
current: {},
incoming: false,
outgoing: true,
showVideo: false,
inProgress: false,
},
},
getters: {
getOutgoing: (state) => state.outgoing,
},
mutations: {
async setPrerequisites(state, payload) {
state.callAgent = payload.callAgent;
state.deviceManager = payload.deviceManager;
state.outgoing.canCall = true;
console.log('payload',await payload.deviceManager.getCameras())
},
userToCall(state, payload) {
state.outgoing.userToCall = payload;
},
setIncomingContext(state, payload) {
state.call.incoming = true;
state.call.outgoing = false;
state.incoming.callerId = payload.callerIdentity.communicationUserId;
state.call.current = payload;
},
setOutgoingContext(state) {
state.call.outgoing = true;
state.call.incoming = false;
state.call.showVideo = false;
state.call.inProgress = true;
},
canCall(state, payload) {
state.outgoing.canCall = payload;
state.outgoing.canHangUp = !payload;
},
callInProgress(state, payload) {
state.call.inProgress = payload;
},
setCall(state, payload) {
state.call.current = payload;
},
setVideo(state, payload) {
state.call.showVideo = payload;
},
hideVideo(state) {
const videoElement = document.getElementById('video');
videoElement.innerHTML = '';
state.call.showVideo = false;
},
},
actions: {
async initPrerequisites({ commit }) {
const callClient = new CallClient();
console.log('in callClient',callClient );
const tokenCredential = new AzureCommunicationTokenCredential('token');
const callAgent = await callClient.createCallAgent(tokenCredential);
console.log(callAgent);
callAgent.on('incomingCall', async function({incomingCall}) {
commit('setIncomingContext', incomingCall);
});
const deviceManager = await callClient.getDeviceManager();
console.log(deviceManager);
commit('setPrerequisites', {callAgent: callAgent, deviceManager: deviceManager});
},
async startCall({ commit, state, dispatch }) {
const camera = await state.deviceManager.getCameras();
var localVideoStream = []
if (camera[0]) {
console.log('camera',camera[0]);
localVideoStream = new LocalVideoStream(camera[0]);
// return localvideostream;
} else {
console.error(`No camera device found on the system`);
}
console.log('localVideoStream',localVideoStream)
// const localVideoStream =return new LocalVideoStream(videoDeviceInfo[0]);
const videoOptions = localVideoStream ? { localVideoStreams: [localVideoStream] } : undefined;
console.log('sai',await state.callAgent.join());
const call = state.callAgent.join(
{ meetingLink: state.meetingLinkInput.value },
{videoOptions},
);
call.on('callEnded', async () => {
commit('setOutgoingContext');
commit('canCall', true);
commit('callInProgress', false);
commit('hideVideo');
});
commit('callInProgress', true);
commit('setCall', call);
commit('setOutgoingContext');
commit('canCall', false);
dispatch('showVideo');
},
hangUp({ commit, state }) {
const call = state.call.current.hangUp({ forEveryone: true });
commit('setCall', call);
commit('setOutgoingContext');
commit('hideVideo');
},
async showVideo({ commit, state }) {
const stream = state.call.current.remoteParticipants[0].videoStreams[0];
const renderer = new Renderer(stream);
const view = await renderer.createView();
commit('setVideo', true);
const videoElement = document.getElementById('video');
videoElement.appendChild(view.target);
},
},
modules: {
},
});