mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
40 lines
881 B
JavaScript
40 lines
881 B
JavaScript
io.Transport.websocket = io.Transport.extend({
|
|
|
|
type: 'websocket',
|
|
|
|
connect: function(){
|
|
var self = this;
|
|
this.socket = new WebSocket(this._prepareUrl());
|
|
this.socket.onmessage = function(ev){ self._onData(ev.data); };
|
|
this.socket.onclose = function(ev){ self._onClose(); };
|
|
return this;
|
|
},
|
|
|
|
send: function(data){
|
|
this.socket.send(data);
|
|
return this;
|
|
},
|
|
|
|
disconnect: function(){
|
|
this.socket.close();
|
|
return this;
|
|
},
|
|
|
|
_onClose: function(){
|
|
this._onDisconnect();
|
|
},
|
|
|
|
_prepareUrl: function(){
|
|
return (this.base.options.secure ? 'wss' : 'ws')
|
|
+ '://' + this.base.host
|
|
+ ':' + this.base.options.port
|
|
+ '/' + this.base.options.resource
|
|
+ '/' + this.type
|
|
+ (this.sessionid ? ('/' + this.sessionid) : '');
|
|
}
|
|
|
|
});
|
|
|
|
io.Transport.websocket.check = function(){
|
|
return 'WebSocket' in window;
|
|
}; |