aircall-everywhere
Advanced tools
Comparing version 1.7.1 to 1.8.0
@@ -1,2 +0,2 @@ | ||
module.exports=function(e){var n={};function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}return t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var r in e)t.d(o,r,function(n){return e[n]}.bind(null,r));return o},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=0)}([function(e,n,t){e.exports=t(1)},function(e,n,t){"use strict";function o(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function r(e,n){for(var t=0;t<n.length;t++){var o=n[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}t.r(n);var i=function(){function e(){var n=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{debug:!0};o(this,e),this.phoneWindow=null,this.integrationSettings={},this.userSettings={},this.eventsRegistered={},this.phoneLoginState=!1;var r=/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/gi;this.phoneUrl=void 0!==t.phoneUrl&&!0===r.test(t.phoneUrl)?t.phoneUrl:"https://phone.aircall.io",this.domToLoadPhone=t.domToLoadPhone,this.integrationToLoad=t.integrationToLoad,this.debug=t.debug,this.size=t.size||"big",this.onLogin=function(){if("function"==typeof t.onLogin&&!1===n.phoneLoginState){n.phoneLoginState=!0;var e={user:n.userSettings};Object.keys(n.integrationSettings).length>0&&(e.settings=n.integrationSettings),t.onLogin(e)}},this.onLogout=function(){"function"==typeof t.onLogout&&t.onLogout()},this.w=t.window||window,this._messageListener(),this.domToLoadPhone&&this._createPhoneIframe()}var n,t,i;return n=e,(t=[{key:"_resetData",value:function(){this.phoneWindow=null,this.integrationSettings={},this.userSettings={},this.phoneLoginState=!1}},{key:"_createPhoneIframe",value:function(){var e="";switch(this.size){case"big":e="height:666px; width:376px;";break;case"small":e="height:600px; width:376px;";break;case"auto":e="height:100%; width:100%;"}try{document.querySelector(this.domToLoadPhone).innerHTML='<iframe allow="microphone; autoplay; clipboard-read; clipboard-write" src="'.concat(this.getUrlToLoad(),'" style="').concat(e,'"></iframe>')}catch(e){this._log("error","[AircallEverywhere] [iframe creation] ".concat(this.domToLoadPhone," not be found. Error:"),e)}}},{key:"_messageListener",value:function(){var e=this;this.w.addEventListener("message",(function(n){if(e._log("info","[AircallEverywhere] [event listener] received event",n),!n.data||!n.data.name||!/^apm_phone_/.test(n.data.name))return!1;if("apm_phone_loaded"!==n.data.name){if("apm_phone_integration_settings"===n.data.name&&n.data.value)return e.integrationSettings=n.data.value,void e.onLogin();if("apm_phone_logout"===n.data.name)return e._resetData(),void e.onLogout();for(var t in e.eventsRegistered)n.data.name==="apm_phone_".concat(t)&&e.eventsRegistered[t](n.data.value)}else e._handleInitMessage(n)}),!1)}},{key:"_handleInitMessage",value:function(e){this.phoneWindow={source:e.source,origin:e.origin},e.data.value&&(this.userSettings=e.data.value),this.phoneWindow.source.postMessage({name:"apm_app_isready"},this.phoneWindow.origin),this.integrationToLoad?this.phoneWindow.source.postMessage({name:"apm_app_get_settings",value:this.integrationToLoad},this.phoneWindow.origin):this.onLogin()}},{key:"_log",value:function(e){var n,t;if("string"!=typeof e)throw new Error("[AircallEverywhere] [_log] Must provide valid console action");if(this.debug){for(var o=arguments.length,r=new Array(o>1?o-1:0),i=1;i<o;i++)r[i-1]=arguments[i];console[e]?(n=console)[e].apply(n,r):(t=console).info.apply(t,r)}}},{key:"getUrlToLoad",value:function(){return"".concat(this.phoneUrl,"?integration=generic")}},{key:"on",value:function(e,n){if(!e||"function"!=typeof n)throw new Error("[AircallEverywhere] [on function] Invalid parameters format. Expected non empty string and function");this.eventsRegistered[e]=n}},{key:"_handleSendError",value:function(e,n){if(e&&e.code||(e={code:"unknown_error"}),e&&!e.message)switch(e.code){case"unknown_error":e.message="Unknown error. Contact aircall developers dev@aircall.io";break;case"no_event_name":e.message="Invalid parameter eventName. Expected an non empty string";break;case"not_ready":e.message='Aircall Phone has not been identified yet or is not ready. Wait for "onLogin" callback';break;case"no_answer":e.message="No answer from the phone. Check if the phone is logged in";break;case"invalid_response":e.message="Invalid response from the phone. Contact aircall developers dev@aircall.io";break;default:e.message="Generic error message"}this._log("error","[AircallEverywhere] [send function] ".concat(e.message)),"function"==typeof n&&n(!1,e)}},{key:"send",value:function(e,n,t){var o=this;if("function"!=typeof n||t||(t=n,n=void 0),!e)return this._handleSendError({code:"no_event_name"},t),!1;if(!this.phoneWindow||!this.phoneWindow.source)return this._handleSendError({code:"not_ready"},t),!1;var r=null;this.phoneWindow.source.postMessage({name:"apm_app_".concat(e),value:n},this.phoneWindow.origin),this.on("".concat(e,"_response"),(function(n){o.removeListener("".concat(e,"_response")),clearTimeout(r),n&&!1===n.success?o._handleSendError({code:n.errorCode,message:n.errorMessage},t):n&&!0===n.success?"function"==typeof t&&t(!0,n.data):o._handleSendError({code:"invalid_response"},t)})),r=setTimeout((function(){o.removeListener("".concat(e,"_response")),o._handleSendError({code:"no_answer"},t)}),2e3)}},{key:"removeListener",value:function(e){var n=this;return!!this.eventsRegistered[e]&&(Object.keys(this.eventsRegistered).filter((function(n){return n===e})).forEach((function(e){return delete n.eventsRegistered[e]})),!0)}},{key:"isLoggedIn",value:function(e){this.send("is_logged_in",(function(n){e(n)}))}}])&&r(n.prototype,t),i&&r(n,i),e}();n.default=i}]); | ||
module.exports=function(e){var n={};function t(o){if(n[o])return n[o].exports;var i=n[o]={i:o,l:!1,exports:{}};return e[o].call(i.exports,i,i.exports,t),i.l=!0,i.exports}return t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var i in e)t.d(o,i,function(n){return e[n]}.bind(null,i));return o},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=0)}([function(e,n,t){e.exports=t(1)},function(e,n,t){"use strict";function o(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function i(e,n){for(var t=0;t<n.length;t++){var o=n[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}t.r(n);var r=function(){function e(){var n=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{debug:!0};o(this,e),this.phoneWindow=null,this.integrationSettings={},this.path=null,this.userSettings={},this.eventsRegistered={},this.phoneLoginState=!1;var i=/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/gi;this.phoneUrl=void 0!==t.phoneUrl&&!0===i.test(t.phoneUrl)?t.phoneUrl:"https://phone.aircall.io",this.domToLoadPhone=t.domToLoadPhone,this.integrationToLoad=t.integrationToLoad,this.path=t.path,this.debug=t.debug,this.size=t.size||"big",this.onLogin=function(){if("function"==typeof t.onLogin&&!1===n.phoneLoginState){n.phoneLoginState=!0;var e={user:n.userSettings};Object.keys(n.integrationSettings).length>0&&(e.settings=n.integrationSettings),t.onLogin(e)}},this.onLogout=function(){"function"==typeof t.onLogout&&t.onLogout()},this.w=t.window||window,this._messageListener(),this.domToLoadPhone&&this._createPhoneIframe()}var n,t,r;return n=e,(t=[{key:"_resetData",value:function(){this.phoneWindow=null,this.path=null,this.integrationSettings={},this.userSettings={},this.phoneLoginState=!1}},{key:"_createPhoneIframe",value:function(){var e="";switch(this.size){case"big":e="height:666px; width:376px;";break;case"small":e="height:600px; width:376px;";break;case"auto":e="height:100%; width:100%;"}try{document.querySelector(this.domToLoadPhone).innerHTML='<iframe allow="microphone; autoplay; clipboard-read; clipboard-write; hid" src="'.concat(this.getUrlToLoad(),'" style="').concat(e,'"></iframe>')}catch(e){this._log("error","[AircallEverywhere] [iframe creation] ".concat(this.domToLoadPhone," not be found. Error:"),e)}}},{key:"_messageListener",value:function(){var e=this;this.w.addEventListener("message",(function(n){if(e._log("info","[AircallEverywhere] [event listener] received event",n),!n.data||!n.data.name||!/^apm_phone_/.test(n.data.name))return!1;if("apm_phone_loaded"!==n.data.name){if("apm_phone_integration_settings"===n.data.name&&n.data.value)return e.integrationSettings=n.data.value,void e.onLogin();if("apm_phone_logout"===n.data.name)return e._resetData(),void e.onLogout();for(var t in e.eventsRegistered)n.data.name==="apm_phone_".concat(t)&&e.eventsRegistered[t](n.data.value)}else e._handleInitMessage(n)}),!1)}},{key:"_handleInitMessage",value:function(e){this.phoneWindow={source:e.source,origin:e.origin},e.data.value&&(this.userSettings=e.data.value),this.phoneWindow.source.postMessage({name:"apm_app_isready",path:this.path},this.phoneWindow.origin),this.integrationToLoad?this.phoneWindow.source.postMessage({name:"apm_app_get_settings",value:this.integrationToLoad},this.phoneWindow.origin):this.onLogin()}},{key:"_log",value:function(e){var n,t;if("string"!=typeof e)throw new Error("[AircallEverywhere] [_log] Must provide valid console action");if(this.debug){for(var o=arguments.length,i=new Array(o>1?o-1:0),r=1;r<o;r++)i[r-1]=arguments[r];console[e]?(n=console)[e].apply(n,i):(t=console).info.apply(t,i)}}},{key:"getUrlToLoad",value:function(){return"".concat(this.phoneUrl,"?integration=generic")}},{key:"on",value:function(e,n){if(!e||"function"!=typeof n)throw new Error("[AircallEverywhere] [on function] Invalid parameters format. Expected non empty string and function");this.eventsRegistered[e]=n}},{key:"_handleSendError",value:function(e,n){if(e&&e.code||(e={code:"unknown_error"}),e&&!e.message)switch(e.code){case"unknown_error":e.message="Unknown error. Contact aircall developers dev@aircall.io";break;case"no_event_name":e.message="Invalid parameter eventName. Expected an non empty string";break;case"not_ready":e.message='Aircall Phone has not been identified yet or is not ready. Wait for "onLogin" callback';break;case"no_answer":e.message="No answer from the phone. Check if the phone is logged in";break;case"invalid_response":e.message="Invalid response from the phone. Contact aircall developers dev@aircall.io";break;default:e.message="Generic error message"}this._log("error","[AircallEverywhere] [send function] ".concat(e.message)),"function"==typeof n&&n(!1,e)}},{key:"send",value:function(e,n,t){var o=this;if("function"!=typeof n||t||(t=n,n=void 0),!e)return this._handleSendError({code:"no_event_name"},t),!1;if(!this.phoneWindow||!this.phoneWindow.source)return this._handleSendError({code:"not_ready"},t),!1;var i=null;this.phoneWindow.source.postMessage({name:"apm_app_".concat(e),value:n},this.phoneWindow.origin),this.on("".concat(e,"_response"),(function(n){o.removeListener("".concat(e,"_response")),clearTimeout(i),n&&!1===n.success?o._handleSendError({code:n.errorCode,message:n.errorMessage},t):n&&!0===n.success?"function"==typeof t&&t(!0,n.data):o._handleSendError({code:"invalid_response"},t)})),i=setTimeout((function(){o.removeListener("".concat(e,"_response")),o._handleSendError({code:"no_answer"},t)}),2e3)}},{key:"removeListener",value:function(e){var n=this;return!!this.eventsRegistered[e]&&(Object.keys(this.eventsRegistered).filter((function(n){return n===e})).forEach((function(e){return delete n.eventsRegistered[e]})),!0)}},{key:"isLoggedIn",value:function(e){this.send("is_logged_in",(function(n){e(n)}))}}])&&i(n.prototype,t),r&&i(n,r),e}();n.default=r}]); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "aircall-everywhere", | ||
"version": "1.7.1", | ||
"version": "1.8.0", | ||
"description": "Library to embed and communicate with aircall-phone in any webpage", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"start": "./scripts/development.sh", | ||
"build": "./scripts/build.sh", | ||
"start": "webpack-dev-server --config scripts/webpack/webpack.dev.js --open", | ||
"build": "webpack --config scripts/webpack/webpack.build.js", | ||
"prepublishOnly": "./scripts/publish.sh", | ||
"test": "karma start --singleRun true scripts/karma.conf.js", | ||
"test-watch": "karma start scripts/karma.conf.js", | ||
"coverage": "karma start --singleRun true --reporters coverage-istanbul scripts/karma.conf.js" | ||
"test": "jest", | ||
"test-watch": "jest --watch", | ||
"coverage": "jest --coverage" | ||
}, | ||
@@ -19,2 +19,8 @@ "husky": { | ||
}, | ||
"jest": { | ||
"coverageReporters": [ | ||
"html", | ||
"json-summary" | ||
] | ||
}, | ||
"repository": { | ||
@@ -31,33 +37,23 @@ "type": "git", | ||
"devDependencies": { | ||
"@babel/core": "^7.4.4", | ||
"@babel/preset-env": "^7.4.4", | ||
"@babel/template": "^7.4.4", | ||
"@babel/types": "^7.4.4", | ||
"babel-loader": "8.0.6", | ||
"babel-plugin-istanbul": "5.1.4", | ||
"babel-plugin-rewire": "1.2.0", | ||
"copy-webpack-plugin": "5.0.3", | ||
"css-loader": "2.1.1", | ||
"gh-pages": "2.0.1", | ||
"html-webpack-plugin": "3.2.0", | ||
"husky": "2.3.0", | ||
"istanbul-instrumenter-loader": "3.0.1", | ||
"jasmine-core": "3.4.0", | ||
"karma": "4.1.0", | ||
"karma-babel-preprocessor": "8.0.0", | ||
"karma-chrome-launcher": "2.2.0", | ||
"karma-coverage": "1.1.2", | ||
"karma-coverage-istanbul-reporter": "2.0.5", | ||
"karma-jasmine": "2.0.1", | ||
"karma-sourcemap-loader": "0.3.7", | ||
"karma-webpack": "^4.0.0-rc.6", | ||
"node-sass": "4.12.0", | ||
"prettier": "1.17.1", | ||
"pretty-quick": "1.11.0", | ||
"sass-loader": "7.1.0", | ||
"style-loader": "0.23.1", | ||
"webpack": "4.41.5", | ||
"webpack-cli": "3.3.10", | ||
"webpack-dev-server": "^3.10.1" | ||
"@babel/core": "^7.11.6", | ||
"@babel/preset-env": "^7.11.5", | ||
"@babel/template": "^7.10.4", | ||
"@babel/types": "^7.11.5", | ||
"babel-loader": "^8.1.0", | ||
"babel-plugin-rewire": "^1.2.0", | ||
"copy-webpack-plugin": "^6.2.0", | ||
"css-loader": "^4.3.0", | ||
"gh-pages": "^3.1.0", | ||
"html-webpack-plugin": "^4.5.0", | ||
"husky": "^4.3.0", | ||
"jest": "^26.4.2", | ||
"node-sass": "^4.14.1", | ||
"prettier": "^2.1.2", | ||
"pretty-quick": "^3.0.2", | ||
"sass-loader": "^10.0.2", | ||
"style-loader": "^1.3.0", | ||
"webpack": "^4.44.2", | ||
"webpack-cli": "^3.3.12", | ||
"webpack-dev-server": "^3.11.0" | ||
} | ||
} |
@@ -27,3 +27,3 @@ # How to use the Aircall Everywhere in any CRM ? | ||
const aircallPhone = new AircallPhone({ | ||
onLogin: settings => { | ||
onLogin: (settings) => { | ||
console.log('phone loaded'); | ||
@@ -35,3 +35,3 @@ doStuff(); | ||
integrationToLoad: 'zendesk', | ||
size: 'big' | ||
size: 'big', | ||
}); | ||
@@ -63,3 +63,3 @@ ``` | ||
```javascript | ||
aircallPhone.isLoggedIn(res => { | ||
aircallPhone.isLoggedIn((res) => { | ||
console.log('login status:', res); | ||
@@ -85,3 +85,3 @@ }); | ||
``` | ||
- `call_end_ringtone`: the ringtone has ended. | ||
- `call_end_ringtone`: the ringtone has ended. This event is only triggered for incoming calls. | ||
```javascript | ||
@@ -104,3 +104,3 @@ { | ||
{ | ||
call_id: 12345 | ||
call_id: 12345; | ||
} | ||
@@ -125,3 +125,3 @@ ``` | ||
{ | ||
phone_number: '+15557543010' | ||
phone_number: '+15557543010'; | ||
} | ||
@@ -145,3 +145,3 @@ ``` | ||
```javascript | ||
aircallPhone.on('incoming_call', callInfos => { | ||
aircallPhone.on('incoming_call', (callInfos) => { | ||
console.log(`Call from ${callInfos.from} to ${callInfos.to}`); | ||
@@ -195,2 +195,32 @@ doStuff(); | ||
## `<iframe>` authorizations | ||
Please be aware that `aircall-everywhere` will generate an iframe with following `allow` attributes. | ||
```html | ||
<iframe | ||
allow="microphone; autoplay; clipboard-read; clipboard-write; hid" | ||
src="https://phone.aircall.io?integration=generic" | ||
style="height:100%; width:100%;" | ||
> | ||
</iframe> | ||
``` | ||
If you need to embed `aircall-everywhere` in an `<iframe>` you own, please be sure to propagate the `allow` attributes like so | ||
```html | ||
<!-- your iframe --> | ||
<iframe src="your src here" allow="camera; microphone; clipboard-read; clipboard-write; hid"> | ||
<!-- iframe generated by aircall-everywhere --> | ||
<iframe | ||
allow="microphone; autoplay; clipboard-read; clipboard-write; hid" | ||
src="https://phone.aircall.io?integration=generic" | ||
style="height:100%; width:100%;" | ||
> | ||
</iframe> | ||
</iframe> | ||
``` | ||
The clipboard API is not accessible through `<iframe>` since Chrome v81 and a policy has been added since Chrome v85. That's why `aircall-everywhere` needs these attributes. More info [here](https://www.chromestatus.com/feature/5767075295395840). | ||
# Development | ||
@@ -197,0 +227,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20
234
33795
8
1