var socket  = require( 'socket.io' );
var express = require('express');
var app     = express();
var server  = require('http').createServer(app);
var io      = socket.listen( server );
var port    = process.env.PORT || 3000;



server.listen(port, function () {
  console.log('Server listening at port %d', port);
});



io.on('connection', function (socket) {

  socket.on( 'yeni_mesaj', function( data ) {
    io.sockets.emit( 'yeni_mesaj', { 
    	yeni_mesaj: data.yeni_mesaj

    });
  });
  
 socket.on( 'kullanici', function( data ) {
    io.sockets.emit( 'kullanici', { 
    	kullanici: data.kullanici,
    	giren: data.giren

    });
  });


  socket.on( 'update_count_message', function( data ) {
    io.sockets.emit( 'update_count_message', {
    	update_count_message: data.update_count_message 
    });
  });

  socket.on( 'new_message', function( data ) {
    io.sockets.emit( 'new_message', {
    	name: data.name,
    	email: data.email,
    	subject: data.subject,
    	created_at: data.created_at,
    	id: data.id
    });
  });

  
});
