Skip to content

Commit

Permalink
v1.4.0: update Alan libs and package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
annmirosh committed Sep 11, 2020
1 parent 65fe627 commit bae0977
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
38 changes: 24 additions & 14 deletions dist/alan_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,10 +615,12 @@ function alanBtn(options) {
var LOW_VOLUME = 'lowVolume';
var PERMISSION_DENIED = 'permissionDenied';
var NO_VOICE_SUPPORT = 'noVoiceSupport';
var NOT_SECURE_ORIGIN = 'notSecureOrigin';

// Error messages
var MIC_BLOCKED_MSG = 'Access to the microphone was blocked. Please allow it to use Alan';
var NO_VOICE_SUPPORT_IN_BROWSER_MSG = 'Your browser doesn’t support voice input. To use voice, open Alan Tutor in a Chrome, Safari, or Firefox desktop browser window.';
var NOT_SECURE_ORIGIN_MSG = 'Audio is allowed only on the secure connection: make sure that your connection protocol is under https, file or http with localhost.';
var LOW_VOLUME_MSG = 'Low volume level';
var OFFLINE_MSG = 'You\'re offline';
var currentErrMsg = null;
Expand Down Expand Up @@ -782,6 +784,9 @@ function alanBtn(options) {
}

function getDefaultBtnState(state) {
if (!isOriginSecure()){
return NOT_SECURE_ORIGIN;
}
if (isAudioSupported()) {
return state || DEFAULT;
}
Expand Down Expand Up @@ -2408,16 +2413,20 @@ function alanBtn(options) {
}
}

if (newState === LOW_VOLUME || newState === PERMISSION_DENIED || newState === NO_VOICE_SUPPORT) {
if (newState === LOW_VOLUME || newState === PERMISSION_DENIED || newState === NO_VOICE_SUPPORT || newState === NOT_SECURE_ORIGIN) {
if (newState === LOW_VOLUME) {
rootEl.classList.add("alan-btn-low-volume");
currentErrMsg = LOW_VOLUME_MSG;
} else if (newState === PERMISSION_DENIED) {
rootEl.classList.add("alan-btn-permission-denied");
currentErrMsg = MIC_BLOCKED_MSG;
} else if (newState === NO_VOICE_SUPPORT) {
} else if (newState === NO_VOICE_SUPPORT || newState === NOT_SECURE_ORIGIN) {
rootEl.classList.add("alan-btn-no-voice-support");
currentErrMsg = NO_VOICE_SUPPORT_IN_BROWSER_MSG;
if (newState === NO_VOICE_SUPPORT) {
currentErrMsg = NO_VOICE_SUPPORT_IN_BROWSER_MSG;
} else if (newState === NOT_SECURE_ORIGIN) {
currentErrMsg = NOT_SECURE_ORIGIN_MSG;
}
}

if (newState === NO_VOICE_SUPPORT) {
Expand Down Expand Up @@ -2532,27 +2541,28 @@ function alanBtn(options) {
return false;
}

function isAudioSupported() {
var available = false,
fakeGetUserMedia,
fakeContext,
isAllowed = false;
function isOriginSecure() {
var isSecure = false;

if (window.location.protocol === 'https:') {
isAllowed = true;
isSecure = true;
}

if (window.location.protocol === 'file:') {
isAllowed = true;
isSecure = true;
}

if (window.location.protocol === 'http:' && window.location.hostname === 'localhost') {
isAllowed = true;
isSecure = true;
}

if (!isAllowed) {
return false;
}
return isSecure;
}

function isAudioSupported() {
var available = false,
fakeGetUserMedia,
fakeContext;

fakeGetUserMedia = (navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
Expand Down
2 changes: 1 addition & 1 deletion dist/alan_lib.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alan-ai/alan-sdk-web",
"version": "1.3.1",
"version": "1.4.0",
"description": "Alan Web SDK: a lightweight JavaScript library for adding a voice experience to your website or web application",
"keywords": [
"alan sdk web",
Expand Down

0 comments on commit bae0977

Please sign in to comment.