-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-SIPJS.html
More file actions
87 lines (77 loc) · 3.43 KB
/
test-SIPJS.html
File metadata and controls
87 lines (77 loc) · 3.43 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
85
86
87
<!DOCTYPE html>
<html>
<head>
<title>SIP.js Browser Test</title>
<!-- SIP.js UMD build from CDN -->
<script src="https://d22gi2hj55ngoj.cloudfront.net/lib/SipJS/sip-0.20.0.min.js"></script>
<!-- Siperb Web Phone UMD build -->
<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 uri = window.SIP.UserAgent.makeURI(`sip:${provisioning.SipUsername}@${provisioning.SipDomain}`);
const wsServer = `wss://${provisioning.SipWssServer}:${provisioning.SipWebsocketPort}/${provisioning.SipServerPath}`;
// Example SIP.js configuration using provisioning details
const sipConfig = {
uri: uri,
authorizationUsername: provisioning.SipUsername,
authorizationPassword: provisioning.SipPassword,
contactName: provisioning.SipContact,
transportOptions: {
server: wsServer
}
// ...other SIP.js options as needed
};
console.log('SIP.js config:', sipConfig);
// Start SIP.js UserAgent
const userAgent = new window.SIP.UserAgent(sipConfig);
await userAgent.start();
console.log('SIP.js UserAgent started.');
// Example: Make an outbound call with custom headers
const target = window.SIP.UserAgent.makeURI("sip:*65@siperb.com"); // Replace with real destination
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
}
const inviter = new window.SIP.Inviter(userAgent, target, options);
await inviter.invite();
console.log('Outbound call initiated with custom headers.');
// End of demonstration
}
window.addEventListener('load', () => {
main();
});
</script>
</head>
<body>
<h1>SIP.js Browser Test</h1>
<p>Open the console to see SIP.js logs and provisioning output.</p>
</body>
</html>