0

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?

Kingpin2k
  • 47,277
  • 10
  • 78
  • 96
JMon
  • 43
  • 6
  • Adapters aren't externally accessible in Ember Data. Looking at this it looks like it's not integrated into Ember Data at all, is there any reason you're using Ember Data? – Kingpin2k Nov 09 '14 at 05:49
  • No, not really. I just started working with ember and didn't really think to use Ember Data. Is that the answer to me getting my data into my web page? – JMon Nov 09 '14 at 14:28
  • 1
    You don't need to use Ember Data (you're using it here: DS.Adapter.extend). Take a read through this: http://stackoverflow.com/questions/24408892/ember-without-ember-data/24411550#24411550 – Kingpin2k Nov 09 '14 at 17:26
  • Ok, thanks. I'm using the ember cli, would you happen to know how I would refer to my adapter in my controller? I tried the name of the file and the name of the file with "Adapter" appended. – JMon Nov 09 '14 at 21:05

0 Answers0