Skip to content

Commit

Permalink
Version 0.3.23
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
InnovateAsterisk committed Jan 18, 2023
1 parent 00c1c69 commit 1206196
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 44 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified Phone/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions Phone/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<link rel="apple-touch-icon" href="icons/512.png">
<link rel="manifest" href="manifest.json">
<script type="text/javascript">
// If you don't want to use a service worker, you can just take this code out.
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register("sw.js").catch(function(error) {
console.error('Service Worker Error', error);
Expand Down
9 changes: 9 additions & 0 deletions Phone/offline.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<title>Browser Phone | Offline</title>
</head>
<body>
<p>Sorry.. the Browser Phone requires you to go online ;)</p>
<p><button onclick="javascript:window.location.reload();">Reload</button></p>
</body>
</html>
95 changes: 88 additions & 7 deletions Phone/phone.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

// Global Settings
// ===============
const appversion = "0.3.22";
const appversion = "0.3.23";
const sipjsversion = "0.20.0";
const navUserAgent = window.navigator.userAgent; // TODO: change to Navigator.userAgentData

Expand Down Expand Up @@ -421,6 +421,59 @@ $(window).on("online", function(){
console.log('Online!');
ReconnectTransport();
});
$(window).on("keypress", function(event) {
// TODO: Add Shortcuts

// console.log(event);
if(event.ctrlKey){
// You have the Ctrl Key pressed, this could be a Call Function
// Blind Transfer the current Call
if(event.key == "b"){
event.preventDefault();
console.log("Keyboard Shortcut for: Start Blind Transfer");
}
// Attended Transfer the current Call
if(event.key == "a"){
event.preventDefault();
console.log("Keyboard Shortcut for: Start Attended Transfer");
}
// Audio Call current selected buddy
if(event.key == "c"){
event.preventDefault();
console.log("Keyboard Shortcut for: Start Audio Call");
}
// Video Call current selected buddy
if(event.key == "v"){
event.preventDefault();
console.log("Keyboard Shortcut for: Start Video Call");
}
// Hold (Toggle)
if(event.key == "h"){
event.preventDefault();
console.log("Keyboard Shortcut for: Hold Toggle");
}
// Mute (Toggle)
if(event.key == "m"){
event.preventDefault();
console.log("Keyboard Shortcut for: Mute Toggle");
}
// End current call
if(event.key == "e"){
event.preventDefault();
console.log("Keyboard Shortcut for: End current call");
}
// Recording (Start/Stop)
if(event.key == "r"){
event.preventDefault();
console.log("Keyboard Shortcut for: Recording Toggle");
}
// Select line 1-9
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"){
event.preventDefault();
console.log("Keyboard Shortcut for: Select Line", event.key);
}
}
});
$(document).ready(function () {
// Load phoneOptions
// =================
Expand Down Expand Up @@ -1472,7 +1525,7 @@ function InitUi(){
catch(e){}
}
}
$("#UserCallID").html(profilePrepend +""+ profileName);
if(profileName) $("#UserCallID").html(profilePrepend +""+ profileName);
$("#UserProfilePic").css("background-image", "url('"+ getPicture("profilePicture") +"')");

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

updateLineScroll(lineNum);
}
function transferOnkeydown(event, obj, lineNum) {
var keycode = (event.keyCode ? event.keyCode : event.which);
if (keycode == '13'){
event.preventDefault();
if(event.ctrlKey){
AttendedTransfer(lineNum);
}
else {
BlindTransfer(lineNum);
}

return false;
}
}
function BlindTransfer(lineNum) {
var dstNo = $("#line-"+ lineNum +"-txt-FindTransferBuddy").val();
if(EnableAlphanumericDial){
Expand Down Expand Up @@ -6961,6 +7028,15 @@ function CancelConference(lineNum){

updateLineScroll(lineNum);
}
function conferenceOnkeydown(event, obj, lineNum) {
var keycode = (event.keyCode ? event.keyCode : event.which);
if (keycode == '13'){
event.preventDefault();

ConferenceDial(lineNum);
return false;
}
}
function ConferenceDial(lineNum){
var dstNo = $("#line-"+ lineNum +"-txt-FindConferenceBuddy").val();
if(EnableAlphanumericDial){
Expand Down Expand Up @@ -8303,11 +8379,16 @@ function handleDialInput(obj, event){
function dialOnkeydown(event, obj, buddy) {
var keycode = (event.keyCode ? event.keyCode : event.which);
if (keycode == '13'){
// if(event.shiftKey || event.ctrlKey)
event.preventDefault();

// Defaults to audio dial
DialByLine('audio');
if(event.ctrlKey && EnableVideoCalling == true){
DialByLine('video');
}
else {
// Defaults to audio dial
DialByLine('audio');
}

return false;
}
}
Expand Down Expand Up @@ -8832,7 +8913,7 @@ function AddLineHtml(lineObj, direction){
// Call Transfer
html += "<div id=\"line-"+ lineObj.LineNumber +"-Transfer\" style=\"text-align: center; line-height:40px; display:none\">";
html += "<div style=\"margin-top:10px\">";
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>";
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>";
html += "<br>"
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>"
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>";
Expand All @@ -8847,7 +8928,7 @@ function AddLineHtml(lineObj, direction){
// Call Conference
html += "<div id=\"line-"+ lineObj.LineNumber +"-Conference\" style=\"text-align: center; line-height:40px; display:none\">";
html += "<div style=\"margin-top:10px\">";
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>";
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>";
html += "<br>"
html += " <button id=\"line-"+ lineObj.LineNumber +"-btn-conference-dial\" onclick=\"ConferenceDial('"+ lineObj.LineNumber +"')\"><i class=\"fa fa-phone\"></i> "+ lang.call +"</button>";
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>";
Expand Down
20 changes: 10 additions & 10 deletions Phone/phone.min.js

Large diffs are not rendered by default.

130 changes: 103 additions & 27 deletions Phone/sw.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const cacheID = "v0";
const ASSETS = [
"index.html",
const CacheItems = [
"index.html", // Special page: Loads from network
"offline.html", // Special page: Save to cache, but return only when offline

"favicon.ico",
"/favicon.ico",

"avatars/default.0.webp",
"avatars/default.1.webp",
Expand All @@ -17,41 +18,116 @@ const ASSETS = [
"wallpaper.dark.webp",
"wallpaper.light.webp",

"media/Alert.mp3",
"media/Ringtone_1.mp3",
"media/speech_orig.mp3",
"media/Tone_Busy-UK.mp3",
"media/Tone_Busy-US.mp3",
"media/Tone_CallWaiting.mp3",
"media/Tone_Congestion-UK.mp3",
"media/Tone_Congestion-US.mp3",
"media/Tone_EarlyMedia-Australia.mp3",
"media/Tone_EarlyMedia-European.mp3",
"media/Tone_EarlyMedia-Japan.mp3",
"media/Tone_EarlyMedia-UK.mp3",
"media/Tone_EarlyMedia-US.mp3",

"https://dtd6jl0d42sve.cloudfront.net/lib/jquery/jquery-3.6.1.min.js",
"https://dtd6jl0d42sve.cloudfront.net/lib/jquery/jquery-ui-1.13.2.min.js",
"https://dtd6jl0d42sve.cloudfront.net/lib/jquery/jquery.md5-min.js",
"https://dtd6jl0d42sve.cloudfront.net/lib/Chart/Chart.bundle-2.7.2.min.js",
"https://dtd6jl0d42sve.cloudfront.net/lib/SipJS/sip-0.20.0.min.js",
"https://dtd6jl0d42sve.cloudfront.net/lib/FabricJS/fabric-2.4.6.min.js",
"https://dtd6jl0d42sve.cloudfront.net/lib/Moment/moment-with-locales-2.24.0.min.js",
"https://dtd6jl0d42sve.cloudfront.net/lib/Croppie/Croppie-2.6.4/croppie.min.js",
"https://dtd6jl0d42sve.cloudfront.net/lib/XMPP/strophe-1.4.1.umd.min.js",

"https://dtd6jl0d42sve.cloudfront.net/lib/Normalize/normalize-v8.0.1.css",
"https://dtd6jl0d42sve.cloudfront.net/lib/fonts/font_roboto/roboto.css",
"https://dtd6jl0d42sve.cloudfront.net/lib/fonts/font_awesome/css/font-awesome.min.css",
"https://dtd6jl0d42sve.cloudfront.net/lib/jquery/jquery-ui-1.13.2.min.css",
"https://dtd6jl0d42sve.cloudfront.net/lib/Croppie/Croppie-2.6.4/croppie.css",

"phone.js",
"phone.css",
"phone.light.css",
"phone.dark.css"

];

self.addEventListener('install', function(event){
console.log("Service Worker: Install");
event.waitUntil(
async function(){
const cache = await caches.open(cacheID);
await cache.addAll(ASSETS);
self.skipWaiting();
}
);
event.waitUntil(caches.open(cacheID).then(function(cache){
console.log("Cache open, adding Items:", CacheItems);
return cache.addAll(CacheItems);
}).then(function(){
console.log("Items Added to Cache, skipWaiting");
// Skip waiting to activate
self.skipWaiting();
}).catch(function(error){
console.warn("Error opening Cache:", error);
// Skip waiting to activate
self.skipWaiting();
}));
});

self.addEventListener('activate', function(event){
console.log("Service Worker: Activate");
event.waitUntil(
async function(){
clients.claim();
}
);
event.waitUntil(clients.claim());
});

self.addEventListener("fetch", (event) => {
event.respondWith(
caches.match(event.request).then(function(response){
if (response) return response;
return fetch(event.request).then(function(response){
return response;
}).catch(function(error) {
console.error(`Fetching failed: ${error}`);
throw error;
});
})
);
self.addEventListener("fetch", function(event){
if(event.request.url.endsWith("index.html")){
console.log("Special Home Page handling...", event.request.url);
event.respondWith(loadHomePage(event.request));
}
else {
// Other Request
event.respondWith(loadFromCacheFirst(event.request));
}
});


const loadFromCacheFirst = async function(request) {
// First try to get the resource from the cache
const responseFromCache = await caches.match(request);
if (responseFromCache) {
return responseFromCache;
}
// Next try to get the resource from the network
try {
const responseFromNetwork = await fetch(request);
if(responseFromNetwork.ok){
// If the request was fine, add it to the cache
addToCache(request, responseFromNetwork.clone());
}
return responseFromNetwork;
}
catch (error) {
return new Response("Network Error", { status: 408, statusText : "Network Error", headers: { "Content-Type": "text/plain" },});
}
}
const loadHomePage = async function(request) {
// First try to get the resource from the network
try {
const responseFromNetwork = await fetch(request);
if(responseFromNetwork.ok){
// Normal Response from server
return responseFromNetwork;
} else {
throw new Error("Server Error");
}
}
catch (error) {
const responseFromCache = await caches.match("offline.html");
if (responseFromCache) {
return responseFromCache;
} else {
return new Response("Network Error", { status: 408, statusText : "Network Error", headers: { "Content-Type": "text/plain" },});
}
}
}
const addToCache = async function(request, response) {
const cache = await caches.open(cacheID);
await cache.put(request, response);
}

0 comments on commit 1206196

Please sign in to comment.