I am trying to set chat.socket = io(); however, when I try to to chat.socket.on I get a value of null. My code is as follows:
var chat = {
loadScript: function(url, callback){
var script = document.createElement( "script" )
script.type = "text/javascript";
if(script.readyState) {
script.onreadystatechange = function() {
if ( script.readyState === "loaded" || script.readyState === "complete" ) {
script.onreadystatechange = null;
callback();
}
};
} else {
script.onload = function() {
callback();
};
}
script.src = url;
document.getElementsByTagName( "head" )[0].appendChild( script );
},
init: function(){
if($('#chat-container .live').length == 0){
console.warn("Live Chat: chat container not found... creating now.");
$('body').append('<div id="chat-container" class="live">');
var chat = $('#chat-container .live');
}else{
var chat = $('#chat-container .live');
}
$('head').append('<link rel="stylesheet" href="//s2.welfordian.com/chat-style" type="text/css" />');
this.loadScript("//s2.welfordian.com/socket.io/socket.io.js", function(){
chat.socket = new io("//s2.welfordian.com");
chat.socket.emit("send_chat_status");
});
},
sendMessage: function(){
}
};
Can anybody see what is causing my problem... or is it just that I cannot set io to be the value of an object property?