From: Pawel Andruszkiewicz Date: Thu, 7 Apr 2016 12:43:50 +0000 (+0200) Subject: [NetworkInformation] Code structure changed to match cordova architecture. X-Git-Tag: submit/tizen/20160411.115901^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cae6bb1a790a50fa59a4fdbbfe4a22530c1c07b3;p=platform%2Fcore%2Fapi%2Fcordova-plugins.git [NetworkInformation] Code structure changed to match cordova architecture. Change-Id: I0bd584511e991e1f9a59abb4f998f111f336998d Signed-off-by: Pawel Andruszkiewicz --- diff --git a/src/cordova-api.gyp b/src/cordova-api.gyp index af8643b..1fc74b9 100644 --- a/src/cordova-api.gyp +++ b/src/cordova-api.gyp @@ -11,7 +11,6 @@ 'cordova/cordova.gyp:*', 'file/cordova_file.gyp:*', 'globalization/cordova_globalization.gyp:*', - 'networkinformation/cordova_networkinformation.gyp:*', ], }, ], # end targets diff --git a/src/lib/cordova_plugins.js b/src/lib/cordova_plugins.js index 9d4303a..ebf0716 100644 --- a/src/lib/cordova_plugins.js +++ b/src/lib/cordova_plugins.js @@ -239,6 +239,19 @@ module.exports = [ "Connection" ] }, + { + "file": "plugins/cordova-plugin-network-information/tizen/NetworkStatus.js", + "id": "cordova-plugin-network-information.tizen.NetworkStatus", + "runs": true + }, + { + "file": "plugins/cordova-plugin-network-information/tizen/Connection.js", + "id": "cordova-plugin-network-information.tizen.Connection", + "clobbers": [ + "navigator.connection", + "navigator.network.connection" + ] + }, { "file": "plugins/cordova-plugin-globalization/www/GlobalizationError.js", "id": "cordova-plugin-globalization.GlobalizationError", diff --git a/src/lib/plugins/cordova-plugin-network-information/tizen/Connection.js b/src/lib/plugins/cordova-plugin-network-information/tizen/Connection.js new file mode 100644 index 0000000..e775328 --- /dev/null +++ b/src/lib/plugins/cordova-plugin-network-information/tizen/Connection.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TODO: remove when added to public cordova repository -> begin +var plugin_name_type = 'cordova-plugin-network-information.tizen.Connection'; + +cordova.define(plugin_name_type, function(require, exports, module) { +//TODO: remove -> end + +var exec = require('cordova/exec'); + +function NetworkConnection() { + this.type = Connection.UNKNOWN; + var that = this; + function successCallback(info) { + that.type = info; + } + + function errorCallback() { + that.type = Connection.UNKNOWN; + } + + function getType() { + exec(successCallback, errorCallback, 'NetworkStatus', 'getConnectionInfo', []); + } + + document.addEventListener('offline', getType); + document.addEventListener('online', getType); +} +var me = new NetworkConnection(); + +module.exports = me; + +//TODO: remove when added to public cordova repository -> begin +}); +// TODO: remove -> end diff --git a/src/lib/plugins/cordova-plugin-network-information/tizen/NetworkStatus.js b/src/lib/plugins/cordova-plugin-network-information/tizen/NetworkStatus.js new file mode 100644 index 0000000..c03af58 --- /dev/null +++ b/src/lib/plugins/cordova-plugin-network-information/tizen/NetworkStatus.js @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TODO: remove when added to public cordova repository -> begin +var plugin_name = 'cordova-plugin-network-information.tizen.NetworkStatus'; + +cordova.define(plugin_name, function(require, exports, module) { +// TODO: remove -> end + +var cordova = require('cordova'); + +function toCordovaConnectionType(type) { + switch (type) { + case 'NONE': + return Connection.NONE; + + case '2G': + return Connection.CELL_2G; + + case '2.5G': + // TODO: In cordova documentation there is no information about 2.5G + // so instead 2G is returned + return Connection.CELL_2G; + + case '3G': + return Connection.CELL_3G; + + case '4G': + return Connection.CELL_4G; + + case 'WIFI': + return Connection.WIFI; + + case 'ETHERNET': + return Connection.ETHERNET; + + default: + return Connection.UNKNOWN; + } +} + +function onSuccessCallback(info) { + var type = toCordovaConnectionType(info.networkType); + + if (Connection.NONE === type || Connection.UNKNOWN === type) { + cordova.fireDocumentEvent('offline'); + } else { + cordova.fireDocumentEvent('online'); + } +} + +function onErrorCallback(e) { + console.error('Error appeared ' + e.name + ', message ' + e.message); +} + +// TODO currently method addPropertyValueChangeListener is registered only to SIM1 and +// ignore changes on SIM2 (if device has dual SIM standby mode). Consider to use +// method addPropertyValueChangeListenerArray to get information from both SIM, but +// which type should be returned then? +tizen.systeminfo.addPropertyValueChangeListener('NETWORK', onSuccessCallback, onErrorCallback); + +exports = { + getConnectionInfo: function(successCallback, errorCallback, args) { + tizen.systeminfo.getPropertyValue('NETWORK', function(info) { + successCallback(toCordovaConnectionType(info.networkType)); + }, function(e){ + if (errorCallback) { + errorCallback(e); + } + }); + } +}; + +require('cordova/exec/proxy').add('NetworkStatus', exports); + +console.log('Loaded cordova.networkinformation API'); + +// TODO: remove when added to public cordova repository -> begin +}); +//TODO: remove -> end diff --git a/src/networkinformation/cordova_networkinformation.gyp b/src/networkinformation/cordova_networkinformation.gyp deleted file mode 100644 index e22a8d1..0000000 --- a/src/networkinformation/cordova_networkinformation.gyp +++ /dev/null @@ -1,25 +0,0 @@ -{ - 'includes':[ - '/usr/include/webapi-plugins/src/common/common.gypi', - ], - 'targets': [ - { - 'target_name': 'tizen_cordova_networkinformation', - 'type': 'loadable_module', - 'sources': [ - 'cordova_networkinformation_api.js', - 'cordova_networkinformation_extension.cc', - 'cordova_networkinformation_extension.h', - ], - 'include_dirs': [ - '../', - '<(SHARED_INTERMEDIATE_DIR)', - ], - 'variables': { - 'packages': [ - 'webapi-plugins', - ], - }, - }, - ], -} diff --git a/src/networkinformation/cordova_networkinformation_api.js b/src/networkinformation/cordova_networkinformation_api.js deleted file mode 100644 index bb013d2..0000000 --- a/src/networkinformation/cordova_networkinformation_api.js +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO: remove when added to public cordova repository -> begin -var plugin_name = 'cordova-plugin-network-information.tizen.NetworkStatus'; - -cordova.define(plugin_name, function(require, exports, module) { -// TODO: remove -> end - -var cordova = require('cordova'); - -function toCordovaConnectionType(type) { - switch (type) { - case 'NONE': - return Connection.NONE; - - case '2G': - return Connection.CELL_2G; - - case '2.5G': - // TODO: In cordova documentation there is no information about 2.5G - // so instead 2G is returned - return Connection.CELL_2G; - - case '3G': - return Connection.CELL_3G; - - case '4G': - return Connection.CELL_4G; - - case 'WIFI': - return Connection.WIFI; - - case 'ETHERNET': - return Connection.ETHERNET; - - default: - return Connection.UNKNOWN; - } -} - -function onSuccessCallback(info) { - var type = toCordovaConnectionType(info.networkType); - - if (Connection.NONE === type || Connection.UNKNOWN === type) { - cordova.fireDocumentEvent('offline'); - } else { - cordova.fireDocumentEvent('online'); - } -} - -function onErrorCallback(e) { - console.error('Error appeared ' + e.name + ', message ' + e.message); -} - -// TODO currently method addPropertyValueChangeListener is registered only to SIM1 and -// ignore changes on SIM2 (if device has dual SIM standby mode). Consider to use -// method addPropertyValueChangeListenerArray to get information from both SIM, but -// which type should be returned then? -tizen.systeminfo.addPropertyValueChangeListener('NETWORK', onSuccessCallback, onErrorCallback); - -exports = { - getConnectionInfo: function(successCallback, errorCallback, args) { - tizen.systeminfo.getPropertyValue('NETWORK', function(info) { - successCallback(toCordovaConnectionType(info.networkType)); - }, function(e){ - if (errorCallback) { - errorCallback(e); - } - }); - } -}; - -require('cordova/exec/proxy').add('NetworkStatus', exports); - -console.log('Loaded cordova.networkinformation API'); - -// TODO: remove when added to public cordova repository -> begin -}); - -var plugin_name_type = 'cordova-plugin-network-information.tizen.NetworkStatus.type'; - -cordova.define(plugin_name_type, function(require, exports, module) { -//TODO: remove -> end - -var exec = require('cordova/exec'); - -function NetworkConnection() { - this.type = Connection.UNKNOWN; - var that = this; - function successCallback(info) { - that.type = info; - } - - function errorCallback() { - that.type = Connection.UNKNOWN; - } - - function getType() { - exec(successCallback, errorCallback, 'NetworkStatus', 'getConnectionInfo', []); - } - - document.addEventListener('offline', getType); - document.addEventListener('online', getType); -} -var me = new NetworkConnection(); - -module.exports = me; - -//TODO: remove when added to public cordova repository -> begin -}); - -exports = function(require) { - require('cordova-tizen').addPlugin('cordova-plugin-network-information.network', plugin_name, 'runs'); - require('cordova-tizen').addPlugin('cordova-plugin-network-information.network', plugin_name_type, 'clobbers', 'navigator.connection'); - require('cordova-tizen').addPlugin('cordova-plugin-network-information.network', plugin_name_type, 'clobbers', 'navigator.network.connection'); -}; -// TODO: remove -> end diff --git a/src/networkinformation/cordova_networkinformation_extension.cc b/src/networkinformation/cordova_networkinformation_extension.cc deleted file mode 100644 index fdcec2e..0000000 --- a/src/networkinformation/cordova_networkinformation_extension.cc +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "networkinformation/cordova_networkinformation_extension.h" - -// This will be generated from cordova_networkinformation_api.js -extern const char kSource_cordova_networkinformation_api[]; - -common::Extension* CreateExtension() { - return new extension::cordova::networkinformation::CordovaNetworkInformationExtension(); -} - -namespace extension { -namespace cordova { -namespace networkinformation { - -CordovaNetworkInformationExtension::CordovaNetworkInformationExtension() { - SetExtensionName("tizen.cordova.networkinformation"); - SetJavaScriptAPI(kSource_cordova_networkinformation_api); -} - -CordovaNetworkInformationExtension::~CordovaNetworkInformationExtension() {} - -} // networkinformation -} // cordova -} // extension diff --git a/src/networkinformation/cordova_networkinformation_extension.h b/src/networkinformation/cordova_networkinformation_extension.h deleted file mode 100644 index 3168b57..0000000 --- a/src/networkinformation/cordova_networkinformation_extension.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef NETWORKINFORMATION_CORDOVA_NETWORKINFORMATION_EXTENSION_H_ -#define NETWORKINFORMATION_CORDOVA_NETWORKINFORMATION_EXTENSION_H_ - -#include - -namespace extension { -namespace cordova { -namespace networkinformation { - -class CordovaNetworkInformationExtension : public common::Extension { - public: - CordovaNetworkInformationExtension(); - virtual ~CordovaNetworkInformationExtension(); -}; - -} // networkinformation -} // cordova -} // extension - -#endif // NETWORKINFORMATION_CORDOVA_NETWORKINFORMATION_EXTENSION_H_