I am attempting to create a web socket for use in my EmberJS app that I have created using the cli. I am a bit unsure of what logic goes where, so let me know if I did this incorrectly.
I have an Adapter that should create a connection and then handle any request that is made to the server that I am connecting to. I am unsure of how to reference this socket in my controller.
export default DS.Adapter.extend({
url: '<my connection bruh>',
qSocket: null,
deferred: $.Deferred(),
defResolve: function(res){
this.deferred.resolve(res);
},
init: function(uri){
var qsservice = this;
if(arguments.length==1&&uri.length>4){
this.url=uri;
}
this.qSocket = new WebSocket(this.url);
this.qSocket.onopen = function(evt){console.log('CONNECTED');};
this.qSocket.onclose = function(evt){console.log('DISCONNECTED');};
this.qSocket.onmessage = function(evt){console.log('RESPONSE: '+evt.data);
qsservice.deferred.resolve(evt.data);};
this.qSocket.onerror = function(evt){console.log('ERROR');
qsservice.deferred.reject(evt);};
},
sendMessage: function (msg) {
return this.qSocket.send(msg);
},
disconnect: function(){
this.qSocket.close();
},
isConnected: function(){
return this.qSocket ? true : false;
},
getDocList: function(){
this.qSocket.send(JSON.stringify(GetDocList));
return this.deferred.promise();
}
});
How would I call any of these functions from, say, the index controller?