Skip to content

Commit

Permalink
minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ukataria committed Feb 9, 2024
1 parent 539f086 commit 6ee3c39
Show file tree
Hide file tree
Showing 3 changed files with 1,895 additions and 2 deletions.
64 changes: 64 additions & 0 deletions calling.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { CallClient } from "@azure/communication-calling";
import { AzureCommunicationTokenCredential } from '@azure/communication-common';

const userToken = document.getElementById("token-input");
const submitToken = document.getElementById("token-submit");

const calleeInput = document.getElementById("callee-id-input");

const callButton = document.getElementById("call-button");
const hangUpButton = document.getElementById("hang-up-button");

let call;
let callAgent;
let tokenCredential;


submitToken.addEventListener("click", async () => {
const callClient = new CallClient();
const userTokenCredential = userToken.value;
try {
tokenCredential = new AzureCommunicationTokenCredential(userTokenCredential);
callAgent = await callClient.createCallAgent(tokenCredential);
callAgent.on('incomingCall', incomingCallHandler);

callButton.disabled = false;
submitToken.disabled = true;
} catch(error) {
window.alert("Please submit a valid token!");
}
})

callButton.addEventListener("click", () => {
// start a call
const userToCall = calleeInput.value;
call = callAgent.startCall(
[{ id: userToCall }],
{}
);

// toggle button states
hangUpButton.disabled = false;
callButton.disabled = true;
});

hangUpButton.addEventListener("click", () => {
// end the current call
call.hangUp({ forEveryone: true });

// toggle button states
hangUpButton.disabled = true;
callButton.disabled = false;
});

const incomingCallHandler = async (args) => {
const incomingCall = args.incomingCall;
console.log("CALL ACCEPTED")
// Accept the call
await incomingCall.accept();

// Subscribe to callEnded event and get the call end reason
incomingCall.on('callEnded', args => {
console.log(args.callEndReason);
});
};
Loading

0 comments on commit 6ee3c39

Please sign in to comment.