-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-JSSIP.html
More file actions
84 lines (74 loc) · 3.27 KB
/
test-JSSIP.html
File metadata and controls
84 lines (74 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html>
<head>
<title>JsSIP Test</title>
<!-- Include JsSIP from CDN -->
<script src="https://cdn.jsdelivr.net/npm/jssip@3/dist/jssip.min.js"></script>
<!-- Include your web phone script if needed -->
<script src="./dist/Siperb-Web-Phone.umd.min.js"></script>
<!-- Include your test script -->
<script>
async function main() {
const accessToken = '<YOUR_PERSONAL_ACCESS_TOKEN>';
let session;
try {
session = await window.Siperb.Login(accessToken);
} catch (error) {
console.error('Failed to get session:', error);
return;
}
// Assume you have a known DeviceToken or use GetDevices as in test.js
// See admin control Panel for generating Script Devices (to get DeviceToken)
const deviceToken = "<YOUR_KNOWN_DEVICE_TOKEN>";
const provisioning = await window.Siperb.GetProvisioning({
UserId: session.UserId,
DeviceToken: deviceToken,
SessionToken: session.SessionToken,
EnableCache: true,
ProvisioningKey: 'SiperbProvisioning'
});
// Build WebSocket server URL
const wsServer = `wss://${provisioning.SipWssServer}:${provisioning.SipWebsocketPort}/${provisioning.SipServerPath}`;
// Example JsSIP configuration using provisioning details
const socket = new window.JsSIP.WebSocketInterface(wsServer);
const configuration = {
sockets: [socket],
uri: `sip:${provisioning.SipUsername}@${provisioning.SipDomain}`,
password: provisioning.SipPassword,
contact_uri: `sip:${provisioning.SipContact || provisioning.ContactUserName}@${provisioning.SipDomain}`,
// ...other JsSIP options as needed
};
console.log('JsSIP config:', configuration);
// Start JsSIP UserAgent
const ua = new window.JsSIP.UA(configuration);
ua.start();
console.log('JsSIP UA started.');
// Example: Make an outbound call with custom headers
const target = 'sip:*65@example.com'; // Replace with real destination
const eventHandlers = {};
const options = {
// If you are connecting to Siperb, then you should also add the following headers to both the REGISTER and INVITE requests
extraHeaders: [
// Your Siperb Session token
`X-Siperb-Sid: ${session.SessionToken}`,
// Your Siperb User ID
`X-Siperb-Uid: ${session.UserId}`,
// Your Siperb JSON web Token
`Authorization: Bearer ${provisioning.SipJwt}`
]
// ...other call options as needed
};
ua.call(target, options);
console.log('Outbound call initiated with custom headers.');
// End of demonstration
}
window.addEventListener('load', () => {
main();
});
</script>
</head>
<body>
<h1>JsSIP Test</h1>
<p>Open the console to see JsSIP logs and provisioning output.</p>
</body>
</html>