Latest Strope.js NOT WORKING -- Strope.Connection is not a constructor?

202 views
Skip to first unread message

Count Klauss

unread,
Nov 6, 2018, 3:19:25 PM11/6/18
to Strophe
I purchased the Worx book " Professional XMPP Programming with JavaScript and jQuery". So far very well done.  Instead of using the old Strophe.js file within the sample code i downloaded the latest Strophjs 1.3.0.  I copied the dist/strophe.js into the sample code's script folder then refreshed.  

I keep getting the error message:

hello.js:57 Uncaught TypeError: Strophe.Connection is not a constructor
    at HTMLDocument.<anonymous> (hello.js:57)
    at HTMLDocument.handle (jquery.js:2693)
    at HTMLDocument.<anonymous> (jquery.js:2468)
    at Object.trigger (jquery.js:2641)
    at HTMLDocument.<anonymous> (jquery.js:2919)
    at Function.each (jquery.js:692)
    at init.each (jquery.js:155)
    at init.trigger (jquery.js:2918)
    at HTMLDivElement.Connect (hello.js:42)
    at HTMLButtonElement.<anonymous> (jquery-ui.js:7387)

The error is occuring within Hello.js on line 57:

57: var conn = new Strophe.Connection("wss://myProsodyServer.com:5281/xmpp-bind/");

Strophe.js library has loaded fine. 

I'm clearly using the latest Strophe.js incorrectly.  I simply downloaded the latest release .zip and pulled its Dist file into my project.  I did not perform any Node/NPM or Browserify do-dats.  

Any ideas on how to get the latest Strophe.js library to work in my sample code from the book would be appreciated.

Hello.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
<html>
<head>
<title>Hello - Chapter 3</title>

<script src='../scripts/strophe.js'></script>

<link rel='stylesheet' href='hello.css'>
<script src='hello.js'></script>
</head>
<body>
<h1>Hello</h1>

<div id='log'>
</div>

<!-- login dialog -->
<div id='login_dialog' class='hidden'>
<label>JID:</label><input type='text' id='jid'>
<label>Password:</label><input type='password' id='password'>
</div>
</body>
</html>

 

Hello.js
var Hello = {
connection: null,
start_time: null,

log: function (msg) {
$('#log').append("<p>" + msg + "</p>");
},

send_ping: function (to) {
var ping = $iq({
to: to,
type: "get",
id: "ping1"
}).c("ping", {
xmlns: "urn:xmpp:ping"
});

Hello.log("Sending ping to " + to + ".");

Hello.start_time = (new Date()).getTime();
Hello.connection.send(ping);
},

handle_pong: function (iq) {
var elapsed = (new Date()).getTime() - Hello.start_time;
Hello.log("Received pong from server in " + elapsed + "ms.");

Hello.connection.disconnect();

return false;
}
};

$(document).ready(function () {
$('#login_dialog').dialog({
autoOpen: true,
draggable: false,
modal: true,
title: 'Connect to XMPP',
buttons: {
"Connect": function () {
$(document).trigger('connect', {
jid: $('#jid').val(),
password: $('#password').val()
});

$('#password').val('');
$(this).dialog('close');
}
}
});
});


$(document).bind('connect', function (ev, data) {
var conn = new Strophe.Connection("wss://myProsodyServer.com:5281/xmpp-bind/");

conn.connect(data.jid, data.password, function (status) {
console.log("\nStatus=" + status);
if (status === Strophe.Status.CONNECTED) {
$(document).trigger('connected');
} else if (status === Strophe.Status.DISCONNECTED) {
$(document).trigger('disconnected');
}
});

Hello.connection = conn;
});

$(document).bind('connected', function () {
// inform the user
Hello.log("Connection established.");

Hello.connection.addHandler(Hello.handle_pong, null, "iq", null, "ping1");

var domain = Strophe.getDomainFromJid(Hello.connection.jid);

Hello.send_ping(domain);

});

$(document).bind('disconnected', function () {
Hello.log("Connection terminated.");

// remove dead connection object
Hello.connection = null;
});

JC Brand

unread,
Nov 9, 2018, 3:33:39 AM11/9/18
to str...@googlegroups.com
Hi,

probably related to this?
https://github.com/strophe/strophejs/issues/311

JC

On Tue, Nov 06, 2018 at 12:09:02PM -0800, Count Klauss wrote:
> I purchased the Worx book "Â Professional XMPP Programming with JavaScript
> and jQuery". So far very well done. Instead of using the old Strophe.js
> file within the sample code i [1]downloaded the latest Strophjs 1.3.0. I
> copied the dist/strophe.js into the sample code's script folder then
> refreshed. Â
> I keep getting the error message:
> hello.js:57 Uncaught TypeError: Strophe.Connection is not a constructor
> Â Â at HTMLDocument.<anonymous> (hello.js:57)
> Â Â at HTMLDocument.handle (jquery.js:2693)
> Â Â at HTMLDocument.<anonymous> (jquery.js:2468)
> Â Â at Object.trigger (jquery.js:2641)
> Â Â at HTMLDocument.<anonymous> (jquery.js:2919)
> Â Â at Function.each (jquery.js:692)
> Â Â at init.each (jquery.js:155)
> Â Â at init.trigger (jquery.js:2918)
> Â Â at HTMLDivElement.Connect (hello.js:42)
> Â Â at HTMLButtonElement.<anonymous> (jquery-ui.js:7387)
> The error is occuring within Hello.js on line 57:
> 57:Â var conn = new Strophe.Connection("wss://myProsodyServer.com:5281/xmpp-bind/");
> Strophe.js library has loaded fine.Â
> I'm clearly using the latest Strophe.js incorrectly. I simply downloaded
> the latest release .zip and pulled its Dist file into my project. I did
> not perform any Node/NPM or Browserify do-dats. Â
> Â
> --
> You received this message because you are subscribed to the Google Groups
> "Strophe" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [2]strophe+u...@googlegroups.com.
> To post to this group, send email to [3]str...@googlegroups.com.
> Visit this group at [4]https://groups.google.com/group/strophe.
> For more options, visit [5]https://groups.google.com/d/optout.
>
> References
>
> Visible links
> 1. http://strophe.im/strophejs/
> 2. mailto:strophe+u...@googlegroups.com
> 3. mailto:str...@googlegroups.com
> 4. https://groups.google.com/group/strophe
> 5. https://groups.google.com/d/optout

JR

unread,
Nov 9, 2018, 10:59:55 AM11/9/18
to str...@googlegroups.com
Oh wow.  Thx JC.  I was thinking maybe i wasnt doing something correctly and so giving up and going to fight through using Stanza.io instead.  I do thank these developers for making these free tools but i wish they'd consider the end-user a bit more in reducing the struggle and fight to get their products to work out of the box.

To unsubscribe from this group and stop receiving emails from it, send an email to strophe+u...@googlegroups.com.
To post to this group, send email to str...@googlegroups.com.
Visit this group at https://groups.google.com/group/strophe.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages