forked from GlobaLexTranslate/GlobaLex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
1,895 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}; |
Oops, something went wrong.