Skip to content

Just trying to make plugin from google's NSD example...

License

Notifications You must be signed in to change notification settings

ThreeSixtyEu/cordova-nsd-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Android NSD example

Just trying to make NSD example work under cordova box...

cordova plugin add https://github.com/perak/cordova-nsd-example.git

Cordova www/index.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>Hello World</title>
		<script type="text/javascript">
			window.onerror=function(msg, url, linenumber) {
				alert('Error message: ' + msg + '\nURL: ' + url + '\nLine Number: ' + linenumber);
				return true;
			}

		</script>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="plugins/DiscoPlugin.js"></script>
        <script type="text/javascript">
			function onLoad() {
				document.addEventListener('deviceready', onDeviceReady, false);
			}

			function onDeviceReady() {
			}

			function showError(s) {
				var logDiv = document.getElementById("logDiv");
				logDiv.innerHTML = "<span style=\"color: red;\">" + s + "</span><br />" + logDiv.innerHTML;
			}

			function showMessage(o) {
				if(o.type == "message") {
					var msgDiv = document.getElementById("msgDiv");
					msgDiv.innerHTML = "<strong>" + o.data + "</strong><br />" + msgDiv.innerHTML;
				}

				if(o.type == "log") {
					var logDiv = document.getElementById("logDiv");
					logDiv.innerHTML = o.data + "<br />" + logDiv.innerHTML;
				}
			}

			function sendMessage() {
				var inputBox = document.getElementById("inputBox");
				window.sendChatMessage(inputBox.value, function(o) { showMessage(o); }, function(e) { showError(e); });
			}
          </script>

    </head>
    <body onload="onLoad()">
        <div class="app">
            <h1>Apache Cordova</h1>
            <div>
            	<button type="button" onclick="window.initChat(function(o) { showMessage(o); }, function(e) { showError(e); }); return false;">Initialize</button>
            	<button type="button" onclick="window.advertizeChat(function(o) { showMessage(o); }, function(e) { showError(e); }); return false;">Advertize</button>
            	<button type="button" onclick="window.discoverChat(function(o) { showMessage(o); }, function(e) { showError(e); }); return false;">Discover</button>
            	<button type="button" onclick="window.connectChat(function(o) { showMessage(o); }, function(e) { showError(e); }); return false;">Connect</button>
            </div>
            <div>
            	<input type="text" id="inputBox"></input>
            	<button type="button" onclick="sendMessage(); return false;">Send</button>
            </div>
            <div id="msgDiv">
            </div>
            <div id="logDiv">
            </div>
        </div>
    </body>
</html>

Add internet permission to your platforms/android/AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />

That's it. :)

About

Just trying to make plugin from google's NSD example...

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 96.0%
  • JavaScript 4.0%