/*jshint node: true, -W106 */
'use strict';

/*
* Name : socket.js
* Module : Lib::PresentationTier::Socket
* Location : /lib/presentationTier
*
* History :
* 
* Version   Date         Programmer         Description
* =========================================================
* 0.0.1     2015-05-17   Samuele Zanella    Initial code
* =========================================================
*/


function Socket(io, nsp) {
	if(nsp===undefined || typeof nsp !=='string' || io.nsps===undefined) {
		console.log('Error: 921');
		return;
	}
	this._namespace = io.of(nsp);
	this._attachedObj=null;
	this._onConnectionEvent='';
}

Socket.prototype.sendMessage = function(event, data) {
	if(event!==undefined && data!==undefined) {
		this._namespace.emit(event, data);
	}
};

Socket.prototype.attachObject = function(obj, onConnectionEvent) {
	if(obj!==undefined && onConnectionEvent!==undefined) {
		this._attachedObj = obj;
		this._onConnectionEvent = onConnectionEvent;
		var nsp=this._namespace;
		/* istanbul ignore next */
		var clientHandle = function (socket) {
			console.log(' new client connected to ' + nsp);
			socket.emit(onConnectionEvent, obj.getConfigJSON());
		};
		this._namespace.on('connection', clientHandle);
	}else{
		console.log('Error: 922');
	}
};

module.exports = Socket;
@@ -1112,16 +1112,18 @@
 sp);%0A%09%09%09
+//
 socket.e
@@ -1167,16 +1167,186 @@
 SON());%0A
+%09%09%09var repeat=function()%7B%0A%09%09%09%09socket.emit(onConnectionEvent, obj.getConfigJSON());%0A%09%09%09%7D;%0A%0A%09%09%09var myVar=setInterval(function () %7Brepeat();%7D, 5000);%0A%09%09%09console.log(myVar);%0A
 %09%09%7D;%0A%09%09t

add repeat Socket onConnection every 5 sec