Skip to content

Commit 1206196

Browse files
Version 0.3.23
Starting to get some shortcuts! and a, now working, service worker that falls back to an offline page. (You can make this page look as you want)
1 parent 00c1c69 commit 1206196

7 files changed

Lines changed: 211 additions & 44 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

Phone/.DS_Store

0 Bytes
Binary file not shown.

Phone/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<link rel="apple-touch-icon" href="icons/512.png">
2020
<link rel="manifest" href="manifest.json">
2121
<script type="text/javascript">
22+
// If you don't want to use a service worker, you can just take this code out.
2223
if ('serviceWorker' in navigator) {
2324
navigator.serviceWorker.register("sw.js").catch(function(error) {
2425
console.error('Service Worker Error', error);

Phone/offline.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<head>
3+
<title>Browser Phone | Offline</title>
4+
</head>
5+
<body>
6+
<p>Sorry.. the Browser Phone requires you to go online ;)</p>
7+
<p><button onclick="javascript:window.location.reload();">Reload</button></p>
8+
</body>
9+
</html>

Phone/phone.js

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
// Global Settings
1717
// ===============
18-
const appversion = "0.3.22";
18+
const appversion = "0.3.23";
1919
const sipjsversion = "0.20.0";
2020
const navUserAgent = window.navigator.userAgent; // TODO: change to Navigator.userAgentData
2121

@@ -421,6 +421,59 @@ $(window).on("online", function(){
421421
console.log('Online!');
422422
ReconnectTransport();
423423
});
424+
$(window).on("keypress", function(event) {
425+
// TODO: Add Shortcuts
426+
427+
// console.log(event);
428+
if(event.ctrlKey){
429+
// You have the Ctrl Key pressed, this could be a Call Function
430+
// Blind Transfer the current Call
431+
if(event.key == "b"){
432+
event.preventDefault();
433+
console.log("Keyboard Shortcut for: Start Blind Transfer");
434+
}
435+
// Attended Transfer the current Call
436+
if(event.key == "a"){
437+
event.preventDefault();
438+
console.log("Keyboard Shortcut for: Start Attended Transfer");
439+
}
440+
// Audio Call current selected buddy
441+
if(event.key == "c"){
442+
event.preventDefault();
443+
console.log("Keyboard Shortcut for: Start Audio Call");
444+
}
445+
// Video Call current selected buddy
446+
if(event.key == "v"){
447+
event.preventDefault();
448+
console.log("Keyboard Shortcut for: Start Video Call");
449+
}
450+
// Hold (Toggle)
451+
if(event.key == "h"){
452+
event.preventDefault();
453+
console.log("Keyboard Shortcut for: Hold Toggle");
454+
}
455+
// Mute (Toggle)
456+
if(event.key == "m"){
457+
event.preventDefault();
458+
console.log("Keyboard Shortcut for: Mute Toggle");
459+
}
460+
// End current call
461+
if(event.key == "e"){
462+
event.preventDefault();
463+
console.log("Keyboard Shortcut for: End current call");
464+
}
465+
// Recording (Start/Stop)
466+
if(event.key == "r"){
467+
event.preventDefault();
468+
console.log("Keyboard Shortcut for: Recording Toggle");
469+
}
470+
// Select line 1-9
471+
if(event.key == "1" || event.key == "2" | event.key == "3" || event.key == "4" || event.key == "5" || event.key == "6" || event.key == "7" || event.key == "8" || event.key == "9"){
472+
event.preventDefault();
473+
console.log("Keyboard Shortcut for: Select Line", event.key);
474+
}
475+
}
476+
});
424477
$(document).ready(function () {
425478
// Load phoneOptions
426479
// =================
@@ -1472,7 +1525,7 @@ function InitUi(){
14721525
catch(e){}
14731526
}
14741527
}
1475-
$("#UserCallID").html(profilePrepend +""+ profileName);
1528+
if(profileName) $("#UserCallID").html(profilePrepend +""+ profileName);
14761529
$("#UserProfilePic").css("background-image", "url('"+ getPicture("profilePicture") +"')");
14771530

14781531
$("#BtnFilter").attr("title", lang.filter_and_sort)
@@ -6497,6 +6550,20 @@ function CancelTransferSession(lineNum){
64976550

64986551
updateLineScroll(lineNum);
64996552
}
6553+
function transferOnkeydown(event, obj, lineNum) {
6554+
var keycode = (event.keyCode ? event.keyCode : event.which);
6555+
if (keycode == '13'){
6556+
event.preventDefault();
6557+
if(event.ctrlKey){
6558+
AttendedTransfer(lineNum);
6559+
}
6560+
else {
6561+
BlindTransfer(lineNum);
6562+
}
6563+
6564+
return false;
6565+
}
6566+
}
65006567
function BlindTransfer(lineNum) {
65016568
var dstNo = $("#line-"+ lineNum +"-txt-FindTransferBuddy").val();
65026569
if(EnableAlphanumericDial){
@@ -6961,6 +7028,15 @@ function CancelConference(lineNum){
69617028

69627029
updateLineScroll(lineNum);
69637030
}
7031+
function conferenceOnkeydown(event, obj, lineNum) {
7032+
var keycode = (event.keyCode ? event.keyCode : event.which);
7033+
if (keycode == '13'){
7034+
event.preventDefault();
7035+
7036+
ConferenceDial(lineNum);
7037+
return false;
7038+
}
7039+
}
69647040
function ConferenceDial(lineNum){
69657041
var dstNo = $("#line-"+ lineNum +"-txt-FindConferenceBuddy").val();
69667042
if(EnableAlphanumericDial){
@@ -8303,11 +8379,16 @@ function handleDialInput(obj, event){
83038379
function dialOnkeydown(event, obj, buddy) {
83048380
var keycode = (event.keyCode ? event.keyCode : event.which);
83058381
if (keycode == '13'){
8306-
// if(event.shiftKey || event.ctrlKey)
83078382
event.preventDefault();
83088383

8309-
// Defaults to audio dial
8310-
DialByLine('audio');
8384+
if(event.ctrlKey && EnableVideoCalling == true){
8385+
DialByLine('video');
8386+
}
8387+
else {
8388+
// Defaults to audio dial
8389+
DialByLine('audio');
8390+
}
8391+
83118392
return false;
83128393
}
83138394
}
@@ -8832,7 +8913,7 @@ function AddLineHtml(lineObj, direction){
88328913
// Call Transfer
88338914
html += "<div id=\"line-"+ lineObj.LineNumber +"-Transfer\" style=\"text-align: center; line-height:40px; display:none\">";
88348915
html += "<div style=\"margin-top:10px\">";
8835-
html += "<span class=searchClean><input id=\"line-"+ lineObj.LineNumber +"-txt-FindTransferBuddy\" oninput=\"QuickFindBuddy(this,'"+ lineObj.LineNumber +"')\" type=text autocomplete=none style=\"width:150px;\" autocomplete=none placeholder=\""+ lang.search_or_enter_number +"\"></span>";
8916+
html += "<span class=searchClean><input id=\"line-"+ lineObj.LineNumber +"-txt-FindTransferBuddy\" oninput=\"QuickFindBuddy(this,'"+ lineObj.LineNumber +"')\" onkeydown=\"transferOnkeydown(event, this, '"+ lineObj.LineNumber +"')\" type=text autocomplete=none style=\"width:150px;\" autocomplete=none placeholder=\""+ lang.search_or_enter_number +"\"></span>";
88368917
html += "<br>"
88378918
html += " <button id=\"line-"+ lineObj.LineNumber +"-btn-blind-transfer\" onclick=\"BlindTransfer('"+ lineObj.LineNumber +"')\"><i class=\"fa fa-reply\" style=\"transform: rotateY(180deg)\"></i> "+ lang.blind_transfer +"</button>"
88388919
html += " <button id=\"line-"+ lineObj.LineNumber +"-btn-attended-transfer\" onclick=\"AttendedTransfer('"+ lineObj.LineNumber +"')\"><i class=\"fa fa-reply-all\" style=\"transform: rotateY(180deg)\"></i> "+ lang.attended_transfer +"</button>";
@@ -8847,7 +8928,7 @@ function AddLineHtml(lineObj, direction){
88478928
// Call Conference
88488929
html += "<div id=\"line-"+ lineObj.LineNumber +"-Conference\" style=\"text-align: center; line-height:40px; display:none\">";
88498930
html += "<div style=\"margin-top:10px\">";
8850-
html += "<span class=searchClean><input id=\"line-"+ lineObj.LineNumber +"-txt-FindConferenceBuddy\" oninput=\"QuickFindBuddy(this,'"+ lineObj.LineNumber +"')\" type=text autocomplete=none style=\"width:150px;\" autocomplete=none placeholder=\""+ lang.search_or_enter_number +"\"></span>";
8931+
html += "<span class=searchClean><input id=\"line-"+ lineObj.LineNumber +"-txt-FindConferenceBuddy\" oninput=\"QuickFindBuddy(this,'"+ lineObj.LineNumber +"')\" onkeydown=\"conferenceOnkeydown(event, this, '"+ lineObj.LineNumber +"')\" type=text autocomplete=none style=\"width:150px;\" autocomplete=none placeholder=\""+ lang.search_or_enter_number +"\"></span>";
88518932
html += "<br>"
88528933
html += " <button id=\"line-"+ lineObj.LineNumber +"-btn-conference-dial\" onclick=\"ConferenceDial('"+ lineObj.LineNumber +"')\"><i class=\"fa fa-phone\"></i> "+ lang.call +"</button>";
88538934
html += " <button id=\"line-"+ lineObj.LineNumber +"-btn-cancel-conference-dial\" style=\"display:none\"><i class=\"fa fa-phone\" style=\"transform: rotate(135deg);\"></i> "+ lang.cancel_call +"</button>";

Phone/phone.min.js

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Phone/sw.js

Lines changed: 103 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const cacheID = "v0";
2-
const ASSETS = [
3-
"index.html",
2+
const CacheItems = [
3+
"index.html", // Special page: Loads from network
4+
"offline.html", // Special page: Save to cache, but return only when offline
45

5-
"favicon.ico",
6+
"/favicon.ico",
67

78
"avatars/default.0.webp",
89
"avatars/default.1.webp",
@@ -17,41 +18,116 @@ const ASSETS = [
1718
"wallpaper.dark.webp",
1819
"wallpaper.light.webp",
1920

21+
"media/Alert.mp3",
22+
"media/Ringtone_1.mp3",
23+
"media/speech_orig.mp3",
24+
"media/Tone_Busy-UK.mp3",
25+
"media/Tone_Busy-US.mp3",
26+
"media/Tone_CallWaiting.mp3",
27+
"media/Tone_Congestion-UK.mp3",
28+
"media/Tone_Congestion-US.mp3",
29+
"media/Tone_EarlyMedia-Australia.mp3",
30+
"media/Tone_EarlyMedia-European.mp3",
31+
"media/Tone_EarlyMedia-Japan.mp3",
32+
"media/Tone_EarlyMedia-UK.mp3",
33+
"media/Tone_EarlyMedia-US.mp3",
34+
35+
"https://dtd6jl0d42sve.cloudfront.net/lib/jquery/jquery-3.6.1.min.js",
36+
"https://dtd6jl0d42sve.cloudfront.net/lib/jquery/jquery-ui-1.13.2.min.js",
37+
"https://dtd6jl0d42sve.cloudfront.net/lib/jquery/jquery.md5-min.js",
38+
"https://dtd6jl0d42sve.cloudfront.net/lib/Chart/Chart.bundle-2.7.2.min.js",
39+
"https://dtd6jl0d42sve.cloudfront.net/lib/SipJS/sip-0.20.0.min.js",
40+
"https://dtd6jl0d42sve.cloudfront.net/lib/FabricJS/fabric-2.4.6.min.js",
41+
"https://dtd6jl0d42sve.cloudfront.net/lib/Moment/moment-with-locales-2.24.0.min.js",
42+
"https://dtd6jl0d42sve.cloudfront.net/lib/Croppie/Croppie-2.6.4/croppie.min.js",
43+
"https://dtd6jl0d42sve.cloudfront.net/lib/XMPP/strophe-1.4.1.umd.min.js",
44+
45+
"https://dtd6jl0d42sve.cloudfront.net/lib/Normalize/normalize-v8.0.1.css",
46+
"https://dtd6jl0d42sve.cloudfront.net/lib/fonts/font_roboto/roboto.css",
47+
"https://dtd6jl0d42sve.cloudfront.net/lib/fonts/font_awesome/css/font-awesome.min.css",
48+
"https://dtd6jl0d42sve.cloudfront.net/lib/jquery/jquery-ui-1.13.2.min.css",
49+
"https://dtd6jl0d42sve.cloudfront.net/lib/Croppie/Croppie-2.6.4/croppie.css",
50+
2051
"phone.js",
2152
"phone.css",
2253
"phone.light.css",
2354
"phone.dark.css"
55+
2456
];
2557

2658
self.addEventListener('install', function(event){
2759
console.log("Service Worker: Install");
28-
event.waitUntil(
29-
async function(){
30-
const cache = await caches.open(cacheID);
31-
await cache.addAll(ASSETS);
32-
self.skipWaiting();
33-
}
34-
);
60+
event.waitUntil(caches.open(cacheID).then(function(cache){
61+
console.log("Cache open, adding Items:", CacheItems);
62+
return cache.addAll(CacheItems);
63+
}).then(function(){
64+
console.log("Items Added to Cache, skipWaiting");
65+
// Skip waiting to activate
66+
self.skipWaiting();
67+
}).catch(function(error){
68+
console.warn("Error opening Cache:", error);
69+
// Skip waiting to activate
70+
self.skipWaiting();
71+
}));
3572
});
73+
3674
self.addEventListener('activate', function(event){
3775
console.log("Service Worker: Activate");
38-
event.waitUntil(
39-
async function(){
40-
clients.claim();
41-
}
42-
);
76+
event.waitUntil(clients.claim());
4377
});
4478

45-
self.addEventListener("fetch", (event) => {
46-
event.respondWith(
47-
caches.match(event.request).then(function(response){
48-
if (response) return response;
49-
return fetch(event.request).then(function(response){
50-
return response;
51-
}).catch(function(error) {
52-
console.error(`Fetching failed: ${error}`);
53-
throw error;
54-
});
55-
})
56-
);
79+
self.addEventListener("fetch", function(event){
80+
if(event.request.url.endsWith("index.html")){
81+
console.log("Special Home Page handling...", event.request.url);
82+
event.respondWith(loadHomePage(event.request));
83+
}
84+
else {
85+
// Other Request
86+
event.respondWith(loadFromCacheFirst(event.request));
87+
}
5788
});
89+
90+
91+
const loadFromCacheFirst = async function(request) {
92+
// First try to get the resource from the cache
93+
const responseFromCache = await caches.match(request);
94+
if (responseFromCache) {
95+
return responseFromCache;
96+
}
97+
// Next try to get the resource from the network
98+
try {
99+
const responseFromNetwork = await fetch(request);
100+
if(responseFromNetwork.ok){
101+
// If the request was fine, add it to the cache
102+
addToCache(request, responseFromNetwork.clone());
103+
}
104+
return responseFromNetwork;
105+
}
106+
catch (error) {
107+
return new Response("Network Error", { status: 408, statusText : "Network Error", headers: { "Content-Type": "text/plain" },});
108+
}
109+
}
110+
const loadHomePage = async function(request) {
111+
// First try to get the resource from the network
112+
try {
113+
const responseFromNetwork = await fetch(request);
114+
if(responseFromNetwork.ok){
115+
// Normal Response from server
116+
return responseFromNetwork;
117+
} else {
118+
throw new Error("Server Error");
119+
}
120+
}
121+
catch (error) {
122+
const responseFromCache = await caches.match("offline.html");
123+
if (responseFromCache) {
124+
return responseFromCache;
125+
} else {
126+
return new Response("Network Error", { status: 408, statusText : "Network Error", headers: { "Content-Type": "text/plain" },});
127+
}
128+
}
129+
}
130+
const addToCache = async function(request, response) {
131+
const cache = await caches.open(cacheID);
132+
await cache.put(request, response);
133+
}

0 commit comments

Comments
 (0)