Page 1 of 1

WAMP API - "Connection is not a constructor"

Posted: Wed May 24, 2017 10:51 pm
by Klexicon
Hello,

I've been beating my head against a wall with this for a few hours now, so I figured I'd come see if anyone could help me solve this issue. I'm trying to set up a WAMP connection in JS. I combined the code from the API section of the help page here with the "require" code at https://github.com/crossbario/autobahn- ... started.md.

Currently the console will log "Ok, Autobahn loaded" and the version number, but then throws an error when I attempt to open the connection. It states that "autobahn.Connection is not a constructor." As far as I can tell from googling, my code should be correct.

Note that I am running this code inside <script> tags in an HTML document and seeing the error in the developer console. My source repository is https://github.com/crossbario/autobahn-js-built. Any assistance is greatly appreciated.

Code: Select all

		require.config({
			baseUrl: ".",
			paths: {
				"autobahn": "\\autobahnJS\\autobahn.min",
				"when": "https://cdnjs.cloudflare.com/ajax/libs/when/2.7.1/when"
			},
			shim: {
				"autobahn": {
					deps: ["when"]
				}
			}
		});
		require(["autobahn"], function(autobahn) {
			console.log("Ok, Autobahn loaded", autobahn.version);
		});
		
		
		var autobahn = require(['autobahn']);
		var wampSession = null;
		var wampUser = 'web';
		var wampPassword = 'web';
		
		var connection = new autobahn.Connection({
			url : 'wss://live.prohashing.com:443/ws',
			realm : 'mining',
			authmethods: ['wampcra'],
			authid: wampUser,
			onchallenge: onChallenge
		});
		
		connection.onopen = connectionOpen;
		connection.open();
		
		function onChallenge(wampSession, method, extra) {
			if (method == 'wampcra') {
				return autobahn.auth_cra.sign(wampPassword, extra.challenge);
			}
		};
		
		function connectionOpen(session, details) {
			wampSession.subscribe('found_block_updates', onBlockUpdate);
			wampSession.call('f_all_miner_updates', ['...api...]).then(initialSessionUpdatesReceived);
		};

Re: WAMP API - "Connection is not a constructor"

Posted: Mon May 29, 2017 8:58 am
by Steve Sokolowski
Klexicon wrote:Hello,

I've been beating my head against a wall with this for a few hours now, so I figured I'd come see if anyone could help me solve this issue. I'm trying to set up a WAMP connection in JS. I combined the code from the API section of the help page here with the "require" code at https://github.com/crossbario/autobahn- ... started.md.

Currently the console will log "Ok, Autobahn loaded" and the version number, but then throws an error when I attempt to open the connection. It states that "autobahn.Connection is not a constructor." As far as I can tell from googling, my code should be correct.

Note that I am running this code inside <script> tags in an HTML document and seeing the error in the developer console. My source repository is https://github.com/crossbario/autobahn-js-built. Any assistance is greatly appreciated.

Code: Select all

		require.config({
			baseUrl: ".",
			paths: {
				"autobahn": "\\autobahnJS\\autobahn.min",
				"when": "https://cdnjs.cloudflare.com/ajax/libs/when/2.7.1/when"
			},
			shim: {
				"autobahn": {
					deps: ["when"]
				}
			}
		});
		require(["autobahn"], function(autobahn) {
			console.log("Ok, Autobahn loaded", autobahn.version);
		});
		
		
		var autobahn = require(['autobahn']);
		var wampSession = null;
		var wampUser = 'web';
		var wampPassword = 'web';
		
		var connection = new autobahn.Connection({
			url : 'wss://live.prohashing.com:443/ws',
			realm : 'mining',
			authmethods: ['wampcra'],
			authid: wampUser,
			onchallenge: onChallenge
		});
		
		connection.onopen = connectionOpen;
		connection.open();
		
		function onChallenge(wampSession, method, extra) {
			if (method == 'wampcra') {
				return autobahn.auth_cra.sign(wampPassword, extra.challenge);
			}
		};
		
		function connectionOpen(session, details) {
			wampSession.subscribe('found_block_updates', onBlockUpdate);
			wampSession.call('f_all_miner_updates', ['...api...]).then(initialSessionUpdatesReceived);
		};
Try contacting JoeTheMiner at memberlist.php?mode=viewprofile&u=1969. While I have only ever implemented our API on our own website (and therefore have little knowledge of Node,) Joe successfully used Node to implement it and maybe he can help you out.