1 var BOSH_SERVICE = 'http://localhost:5280/http-bind/';
3 Strophe.addNamespace("ADHOC", "http://jabber.org/protocol/commands");
9 var entry = $('<div></div>').append(document.createTextNode(msg));
10 $('#log').append(entry);
13 function rawInput(data) {
17 function rawOutput(data) {
21 function onConnect(status) {
22 if (status == Strophe.Status.CONNECTING) {
23 log('Strophe is connecting.');
24 } else if (status == Strophe.Status.CONNFAIL) {
25 log('Strophe failed to connect.');
27 } else if (status == Strophe.Status.DISCONNECTING) {
28 log('Strophe is disconnecting.');
29 } else if (status == Strophe.Status.DISCONNECTED) {
30 log('Strophe is disconnected.');
32 } else if (status == Strophe.Status.AUTHFAIL) {
33 log('Authentication failed');
35 connection.disconnect();
37 } else if (status == Strophe.Status.CONNECTED) {
38 log('Strophe is connected.');
43 function displayResult(result) {
44 var status = $(result).find("command").attr("status");
46 $("#output *").remove();
47 $(result).find("note").each(function(index, e) {
48 type = $(e).attr("type");
52 $("#output").append("<p class='" + type + "Note'>" + $(e).text() + "</p>");
54 if (status == "executing") {
55 $("#output").append("<input type='button' disabled='true' id='prevButton' value='prev'/>"+
56 "<input type='button' disabled='true' id='nextButton' value='next'/>"+
57 "<input type='button' disabled='true' id='completeButton' value='complete'/>"+
58 "<input type='button' id='executeButton' value='execute'/>");
59 for (kind in ['prev', 'next', 'complete']) {
60 if ($(result).find('actions ' + kind).length > 0)
61 $('#' + kind + 'Button').attr("disabled", "false");
64 input = $("<input type='button' value='Restart'/>").bind("click", function() {
65 $('#output *').remove();
68 $("#output").append(input);
72 function runCommand() {
73 execIQ = $iq({ type: "set", to: "localhost", id: connection.getUniqueId() })
74 .c("command", { xmlns: Strophe.NS.ADHOC, node: $(this).attr("id"),
76 connection.sendIQ(execIQ, displayResult);
79 function getCommandNodes() {
80 nodesIQ = $iq({ type: "get", to: "localhost", id: "nodes1" }).c("query", {xmlns: Strophe.NS.DISCO_ITEMS, node: Strophe.NS.ADHOC});
81 connection.sendIQ(nodesIQ, function(result) {
82 $('#output').append("<ul id='items'></ul>");
83 $(result).find("item").each(function(index, e) {
84 item = $("<li id='" + $(e).attr("node") + "'>" + $(e).attr("name") + "</li>").bind("click", runCommand);
85 $("#items").append(item);
90 function checkFeatures() {
91 featureIQ = $iq({ type: "get", to: "localhost", id: "features1" }).c("query", {xmlns: Strophe.NS.DISCO_INFO});
92 connection.sendIQ(featureIQ, function(result) {
93 if ($(result).find("feature[var='" + Strophe.NS.ADHOC + "']").length > 0) {
94 $('#output').append("<p>This entitiy does support AdHoc commands</p>");
96 $('#output').append("<p>This entitiy does NOT support AdHoc commands</p>");
102 function showConnect() {
104 var pass = $('#pass');
105 var button = $('#connect').get(0);
107 button.value = 'connect';
111 $('#output *').remove();
115 function showDisconnect() {
117 var pass = $('#pass');
118 var button = $('#connect').get(0);
120 button.value = 'disconnect';
127 $(document).ready(function () {
128 connection = new Strophe.Connection(BOSH_SERVICE);
129 connection.rawInput = rawInput;
130 connection.rawOutput = rawOutput;
132 $("#log_toggle").click(function () {
136 $('#cred').bind('submit', function () {
137 var button = $('#connect').get(0);
139 var pass = $('#pass');
140 localJID = jid.get(0).value;
142 if (button.value == 'connect') {
144 $('#log *').remove();
145 connection.connect(localJID,
149 connection.disconnect();
155 onunload = function() {
157 connection.disconnect();