the problem is that the server variable is being defined in server.js as that is where the web server is created and the socket.io binds to the listening port. As I have split it into separate modules it is though I should somehow being making the variable global so that it can be referenced.
--
Thanks, Phil
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
server.start(asterisk);
and then in server.js I changed the start function to be:
function start(asterisk) {
...
...
asterisk()
}
asterisk.js has then been updated to export itself as:
function asterisk() {
}
exports.asterisk = asterisk;
if I then run node index.js and the server does begin to start but when it hits the asterisk call I receive:
[uxbod@cyborg asterisk]$ node index.js
info - socket.io started
info - Web server has started on port 8080
node.js:218
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: object is not a function
at Object.start (/home/uxbod/Development/nodejs/asterisk/server.js:33:5)
at Object.<anonymous> (/home/uxbod/Development/nodejs/asterisk/index.js:4:8)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:32)
at Function._load (module.js:310:12)
at Array.0 (module.js:484:10)
at EventEmitter._tickCallback (node.js:209:41)
I thought by passing asterisk as a function to the server then the socket would be available to the asterisk function ? Confused ?!?!? :(
I guess with it all being new it is taking a while to sync in :) I now have a server and a client that when I go to the web page and enter the URL it displays the data that has been emitted. The next step was to have the web page automatically update every few seconds so that new events would automatically update the div. This is the HTML I tried:
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="/socket.io/socket.io.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script language="javascript">
var socket = io.connect("http://localhost");
var auto_refresh = setInterval( function() {
socket.on("event", function(data) {
$("#event_text").text(data.exten);
})
}, 2000);
</script>
</head>
<body>
<b>Some event happened=<div id="event_text"></div></b>
</body>
</html>
Now if I click on refresh it works fine; but I am wondering that when the setInterval is wrapper around the socket.on() it fails to contact the server side again.
How would you approach it as I don't want to refresh the whole page just the indivdual div element.
--
Thanks, Phil