/**
 * ember-sockets adapater script
 * app/adapters/application.js 
 * by Paul Robbins (ShopApps Ltd) created on 2014-09-15 
 * www.shopapps.co.uk
 * paul@shopapps.co.uk
 *
 * NOTES:  This is a ember-cli file used to create a socket adapter
  to use, change the line in the init: function where it says window.Myapp.__container__ 
  so that Myapp is the name of your App 
 */
import Ember from 'ember';
import DS from "ember-data";

export default DS.Adapter.extend({
	needs: ['application'],
	init: function() {
		console.log("STARTING SOCKET ADAPTER");
		/*
		 * Put your module name here (relace Myapp).
		 * todo: find a better method of getting the socket reference...
		 */
		this.socket = window.Myapp.__container__.lookup('socket:Main');
		this._super();
	},
	
	makeSocketRequest : function (store, eventType, query) {

        var adapter = this;
        /*
        * todo: better manage when a socket is not yet connected
        * need some kind of setTimeout or similar?
        */
        return new Ember.RSVP.Promise(function (resolve, reject) {
            try {
            	if(!adapter.socket.socket.connected)
                {
            		console.log('[Adapter] App.Socket is not yet connected');
            		reject({ message : 'App.Socket is not yet connected'});
                }
            	else
            	{
	                if (adapter.socket.authenticated) {
	                	adapter.socket.emit(eventType, query, function (data) {
	                		console.log('[Adapter] response?', data);
	                        if (data.status) {
	                            resolve(data.content);
	                        } else {
	                            reject(data);
	                        }
	                    });
	                } else {
	                	console.log('[Adapter] App.Socket is not authenticated');
	                    reject({ message : 'App.Socket is not authenticated'});
	                }
            	}
            } catch (e) {
            	console.error('[Adapter] App.Socket is not available for requests', e);
                reject({ message : 'App.Socket is not available for requests'});
            }
        });
        

    },

    find: function (store, type, id) {
    	console.log('[Adapter] FIND: ', type.typeKey);
        return this.makeSocketRequest(store, 'find', {
            type : type.typeKey,
            query : { id : id }
        });
    },
    
    
	findAll: function(store, type, id) {
		console.log('[Adapter] FINDALL: ', type.typeKey, id);
		return this.makeSocketRequest(store, 'findAll', {
            type : type.typeKey,
            query : { since : id }
        });

		
	},
	findQuery: function(store, type, query) {
		return this.makeSocketRequest(store, 'findQuery', {
            type : type.typeKey,
            query : query
        });
	},
	findMany: function(store, type, ids, records) {
		return this.makeSocketRequest(store, 'findMany', {
            type : type.typeKey,
            query : { ids : ids }
        });
	},
	findBelongsTo: function(store, record, url) {
		var id = this.get(record, 'id');
		var type = record.constructor.typeKey;
		console.log('[Adapter] findBelongsTo: ', type, url);
		return this.makeSocketRequest(store, 'findBelongsTo', {
            type : type,
            query : { id : id }
        });
	},
	findHasMany: function(store, record, url) {
		var id = this.get(record, 'id');
		var type = record.constructor.typeKey;
		console.log('[Adapter] findHasMany: ', type, url);
		this.makeSocketRequest(store, 'findHasMany', {
            type : type,
            query : { id : id }
        });
	}
	
	
});

@@ -239,143 +239,12 @@
 ter%0A
-  to use, change the line in the init: function where it says window.Myapp.__container__ %0A  so that Myapp is the name of your App %0A
  */%0A
+
 impo
@@ -424,162 +424,30 @@
 ;%0A%09%09
-/*
 %0A%09%09
- * Put your module name here (relace Myapp).%0A%09%09 * todo: find a better method of getting the socket reference...%0A%09%09 */%0A%09%09this.socket = window.Myapp.__
+this.socket = this.
 cont
@@ -455,10 +455,8 @@
 iner
-__
 .loo
@@ -471,14 +471,21 @@
 ket:
-M
+m
 ain')
+.socket
 ;%0A%09%09
@@ -815,16 +815,16 @@
   try %7B%0A
+
         
@@ -847,23 +847,16 @@
 .socket.
-socket.
 connecte

Update application.js