You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2016/12/09 00:58:28 UTC

cordova-plugins git commit: TCP Socket working for FxOS

Repository: cordova-plugins
Updated Branches:
  refs/heads/master 08ab173a3 -> bb1635677


TCP Socket working for FxOS

 This closes #21


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugins/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugins/commit/bb163567
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugins/tree/bb163567
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugins/diff/bb163567

Branch: refs/heads/master
Commit: bb1635677745540c0d6c0f7f00c6e27ff94f4282
Parents: 08ab173
Author: Piotr Zalewa <pi...@zalewa.info>
Authored: Mon Mar 16 14:10:02 2015 +0100
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Thu Dec 8 17:00:08 2016 -0800

----------------------------------------------------------------------
 tcpsocket/doc/index.md                    | 60 ++++++++++++++++++++++++++
 tcpsocket/plugin.xml                      | 49 +++++++++++++++++++++
 tcpsocket/src/firefoxos/TCPSocketProxy.js | 47 ++++++++++++++++++++
 tcpsocket/www/TCPSocket.js                | 51 ++++++++++++++++++++++
 4 files changed, 207 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/bb163567/tcpsocket/doc/index.md
----------------------------------------------------------------------
diff --git a/tcpsocket/doc/index.md b/tcpsocket/doc/index.md
new file mode 100644
index 0000000..7f840a1
--- /dev/null
+++ b/tcpsocket/doc/index.md
@@ -0,0 +1,60 @@
+<!---
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you 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.
+-->
+
+# org.apache.cordova.labs.tcpsocket
+
+This plugin is used to run sockets
+
+## Objects
+
+- navigator.TCPSocket
+
+## Methods
+
+### navigator.TCPSocket.open
+
+	navigator.TCPSocket.open(host, port, successCallback, errorCallback, options)
+
+
+- host is a string representing the hostname of the server to connect to (it can also be its raw IP address).
+- port is a umber representing the TCP port to be used by the socket (some protocols have a standard port, for example 80 for HTTP, 447 for SSL, 25 for SMTP, etc. Port numbers beyond 1024 are not assigned to any specific protocol and can be used for any purpose.)
+- options is an object containing
+	- useSecureTransport (Boolean) false (default)
+	- binaryType (String) "string" (default) or "arrayBuffer"
+
+an instantiation of a new TCPSocket object is returned in success callback
+
+#### Firefox OS quirks
+
+Only certified apps can use a port below 1024.
+
+### navigator.TCPSocket.listen
+
+	navigator.TCPSocket.listen(port, successCallback, errorCallback, options, queueLimit)
+
+- port is a number representing the TCP port to be used to listen for connections. 
+- options is an optional object expecting a property called binaryType which is a string that can have two possible values: string and arraybuffer. If the value is arraybuffer then the TCPSocket.send() will use ArrayBuffers and the data received from the remote connection will also be available in that format.
+- queueLimit is a number representing the maximum lenght that the pending connections queue can grow.
+
+an instantiation of a new TCPSocket object is returned in success callback
+
+#### Firefox OS quirks
+
+Only certified apps can use a port below 1024.
+

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/bb163567/tcpsocket/plugin.xml
----------------------------------------------------------------------
diff --git a/tcpsocket/plugin.xml b/tcpsocket/plugin.xml
new file mode 100644
index 0000000..8bb3d03
--- /dev/null
+++ b/tcpsocket/plugin.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you 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.
+-->
+
+<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
+    id="org.apache.cordova.labs.tcpsocket"
+    version="0.0.1">
+    <name>TCPSocket</name>
+    <description>Cordova TCP Socket Plugin</description>
+    <license>Apache 2.0</license>
+    <keywords>cordova,tcpsocket,socket,tcp</keywords>
+
+
+	<engines>
+		<engine name="cordova" version=">=3.6.0" />
+	</engines>
+
+    <js-module src="www/TCPSocket.js" name="TCPSocket">
+        <clobbers target="navigator.TCPSocket" />
+    </js-module>
+
+    <!-- firefoxos -->
+    <platform name="firefoxos">
+        <config-file target="config.xml" parent="/*">
+            <permission name="tcp-socket" description="Required for accessing TCP Socket"
+                        privileged="true"/>
+        </config-file>
+        <js-module src="src/firefoxos/TCPSocketProxy.js" name="TCPSocketProxy">
+            <runs />
+        </js-module>
+    </platform>
+</plugin>
+

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/bb163567/tcpsocket/src/firefoxos/TCPSocketProxy.js
----------------------------------------------------------------------
diff --git a/tcpsocket/src/firefoxos/TCPSocketProxy.js b/tcpsocket/src/firefoxos/TCPSocketProxy.js
new file mode 100644
index 0000000..bbdf1fa
--- /dev/null
+++ b/tcpsocket/src/firefoxos/TCPSocketProxy.js
@@ -0,0 +1,47 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+var mozTCPSocket = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.TCPSocket') || navigator.mozTCPSocket;
+
+function open(successCB, errorCB, options) {
+    try {
+        var socket = mozTCPSocket.open(options.host, options.port, options.setup);
+    } catch (e) {
+        errorCB(e);
+        return;
+    }
+    successCB(socket);
+}
+
+function listen(successCB, errorCB, options) {
+    try {
+        var socket = mozTCPSocket.listen(options.port, options.setup, options.queueLimit);
+    } catch (e) {
+        errorCB(e);
+        return;
+    }
+    successCB(socket);
+}
+
+require('cordova/exec/proxy').add('TCPSocket', {
+  open: open,
+  listen: listen
+});

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/bb163567/tcpsocket/www/TCPSocket.js
----------------------------------------------------------------------
diff --git a/tcpsocket/www/TCPSocket.js b/tcpsocket/www/TCPSocket.js
new file mode 100644
index 0000000..b2ab013
--- /dev/null
+++ b/tcpsocket/www/TCPSocket.js
@@ -0,0 +1,51 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+*/
+
+var cordova = require('cordova'),
+    exec = require('cordova/exec');
+
+var TCPSocket = {
+    open: function(host, port, successCB, errorCB, setup) {
+      setup = setup || {};
+      setup.useSecureTransport = setup.useSecureTransport || false;
+      setup.binaryType = setup.binaryType || 'string'; 
+      options = {
+        host: host,
+        port: port,
+        setup: setup
+      }
+      exec(successCB, errorCB, "TCPSocket", "open", options)
+    },
+    listen: function(port, successCB, errorCB, setup, queueLimit) {
+      setup = setup || {};
+      setup.binaryType = setup.binaryType || 'string'; 
+      options = {
+        port: port,
+        setup: setup
+      };
+      if (queueLimit) {
+          options.queueLimit = queueLimit;
+      }
+      exec(successCB, errorCB, "TCPSocket", "listen", options)
+    }
+}
+
+module.exports = TCPSocket;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org