'use strict';
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);

// var socket = require('socket.io');
// var express = require('express');
// var http = require('http');

// var app = express();
// var server = http.createServer(app);

// var io = socket.listen(server);

require('dotenv').config();


console.log(process.env.REDIS_PORT);
console.log(process.env.REDIS_HOST);


var redisPort = process.env.REDIS_PORT;
var redisHost = process.env.REDIS_HOST;
var ioRedis = require('ioredis');
var redis = new ioRedis(redisPort, redisHost);
redis.subscribe('action-channel-one');
redis.on('message', function (channel, message) {
  message  = JSON.parse(message);
  io.emit(channel + ':' + message.event, message.data);
});

var broadcastPort = process.env.BROADCAST_PORT;
server.listen(broadcastPort, function () {
  console.log('Socket server is running.');
});