Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
logsol
committed
Mar 23, 2012
1 parent
3f6bf90
commit 8902009
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
function Connector(){ | ||
this.ip = null; | ||
this.port = null; | ||
this.socket = null; | ||
} | ||
|
||
Connector.prototype.connect = function(ip, port){ | ||
var self = this; | ||
this.ip = ip; | ||
this.port = port; | ||
|
||
if(window.io === undefined){ | ||
self.onError('io not found (chatserver seems down)'); | ||
return false; | ||
} | ||
|
||
this.socket = io.connect(this.ip + ':' + this.port); | ||
this.socket.reconnecting = false; | ||
} | ||
|
||
Connector.prototype.registerEvent = function(name, callback){ | ||
this.socket.on(name, callback); | ||
} | ||
|
||
Connector.prototype.send = function(method, data){ | ||
var transfer = { | ||
method: method, | ||
data: data | ||
}; | ||
transfer = JSON.stringify(transfer); | ||
this.socket.send(transfer); | ||
console.log('sending: ' + transfer); | ||
} | ||
|
||
Connector.prototype.onError = function(message){ | ||
console.log(message); | ||
} |
Oops, something went wrong.