Skip to content

Commit

Permalink
Before moving to Angular
Browse files Browse the repository at this point in the history
  • Loading branch information
tameeshB committed Dec 18, 2017
1 parent 71b7a2b commit a38f0ef
Show file tree
Hide file tree
Showing 10 changed files with 371 additions and 24 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions public/css/chat.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
html,body {
font-family: 'Open Sans', serif;
/* font-family: 'Open Sans', serif; */
font-size: 14px;
line-height: 1.5;
height: 100%;
Expand Down Expand Up @@ -51,7 +51,7 @@ html,body {
.messages {
display:block;
z-index: 1;
/* box-shadow: #000000 5px 1px 20px 2px; */
box-shadow: #000000 -5px -1px 20px 0px;
}
.message {
display:block;
Expand Down
2 changes: 1 addition & 1 deletion public/css/landing.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
html,body {
background: #EFF3F4;
/* background-image: url('/images/bg/login_blue.jpg'); */
font-family: 'Open Sans', serif;
/* font-family: 'Open Sans', serif; */
}
.hero{

Expand Down
2 changes: 1 addition & 1 deletion public/css/login.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
html,body {
font-family: 'Open Sans', serif;
/* font-family: 'Open Sans', serif; */
font-size: 14px;
background-image: url('/images/bg/login_blue.jpg');

Expand Down
294 changes: 294 additions & 0 deletions public/js/angular.min.js

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions public/js/chat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(function () {
var app = angular.module('sockchat', []);

app.controller('StoreController', function () {
this.product = gem;
});


app.controller('ReviewController', function () {
this.review = {};

this.addReview = function (product) {
product.reviews.push(this.review);

this.review = {};
};
});
})();
1 change: 0 additions & 1 deletion public/js/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ $(function () {
var $message = $("#msgTextBox");
var $chat = $("#inbox-messages");
//onload init

socket.emit('connected', {username: myuser, hash: userhash}, function (data) {
if (data) {
$("#userFormArea").fadeOut();
Expand Down
3 changes: 1 addition & 2 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ module.exports = function(app, passport, db) {
},function(err,docs){
if(err)
console.log(err);
rooms = docs;
console.log('DBGROOMS');
rooms = docs;
//filter message history
//message remodel
db.messages.find({
Expand Down
62 changes: 49 additions & 13 deletions server_sockets.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@

require('./globals');
var async = require('async');
var wait = require('wait.for');
var bcrypt = require('bcrypt-nodejs');
module.exports = function(app, io, db) {
var connections= [];
var online = [];//points to online users?
var onlineUsers = [];
//sockets
var socketonline = [];
io.sockets.on('connection',function(socket){
Expand All @@ -16,6 +19,7 @@ module.exports = function(app, io, db) {
else
socketonline[r.roomname] = [socket.id];
});
onlineUsers.push(userGL.username);
// console.log("conn:socketonline",socketonline);
//disconnect
socket.on('disconnect',function(data){
Expand All @@ -28,6 +32,7 @@ module.exports = function(app, io, db) {
roomsGL.forEach(function (r) {
socketonline[r.roomname].splice(socketonline.indexOf(socket.id),1);
});
onlineUsers.splice(onlineUsers.indexOf(userGL.username), 1);
console.log("disc:socketonline", socketonline);
});

Expand All @@ -39,7 +44,7 @@ module.exports = function(app, io, db) {
socket.on('connected', function (data, callback){
// console.log('connected:',data);
callback(true);
var myRooms = userGL.rooms;
var myRooms = userGL.rooms.map(function(a){return a.roomname});
//lets remodel all room objects with name + id, that'll make stuff a lot non-SQL-y
//#makethemostoutofmongo
//verify user
Expand All @@ -48,28 +53,59 @@ module.exports = function(app, io, db) {
socket.username = data.username;
console.log('\x1b[36m%s\x1b[0m', userGL);
// console.log('\x1b[36m%s\x1b[0m', roomsGL);
userGL.rooms.forEach(function(r){//for all rooms that i'm a part of,
//add me as a online user
console.log('=1',roomsGL);

// async.each(roomsGL, function (nameroomObj, callback) {
// if (online[nameroomObj.roomname])
// online[nameroomObj.roomname].push(data.username);
// else
// online[nameroomObj.roomname] = [data.username];
// callback();
// }, function (err) {
// if (err) { return console.log(err); }
// var postConnectObject = {
// status: 200,
// rooms: myRooms,//only rooms you are a part of
// online: online //online members in each room
// };
// console.log('=4', postConnectObject);
// socket.emit('post connect', postConnectObject);
// });
var onlineCount =0;
roomsGL.forEach(function(r){//for all rooms that i'm a part of,
console.log('=2', r);
//add me as a online user
// online[r].push(data.username);
// online.push(data.username);//@todo move to intended 2d arch.
if(online[r])
online[r].push(data.username);
if(online[r.roomname])
online[r.roomname].push(data.username);
else
online[r] = [data.username];
})
online[r.roomname] = [data.username];
})
onlineCount++;
// online.push(data.username);//@todo remove.
// });
//update online users list with this new user
//so i can either append to a list of all rooms just the online users //could do that for now
// or something that shows who is active and who is not?
//rather just go with an object model with room object and ng- it with some js framework, angular? that parts later... program the sockets first...
//so just the online users in each array inside the rooms object.
//voila, could combine both arrays in O(1) and remove dupes using the new Set() method, find some method to keep the first one...
socket.emit('post connect',{
status: 200,
rooms: myRooms,//only rooms you are a part of
online: online //online members in each room
});
//voila, could combine both arrays in O(1) and remove dupes using the new Set() method, find some method to keep the first one...
var runFlag =0;
console.log('=3', online, online.length);
console.log('=5', roomsGL, roomsGL.length);
setInterval(function(){
if (roomsGL.length <= onlineCount && runFlag == 0){
var postConnectObject = {
status: 200,
rooms: myRooms,//only rooms you are a part of
online: online //online members in each room
};
console.log('=4', postConnectObject);
socket.emit('post connect', postConnectObject);
runFlag =1;
}
},500)
}else{
io.sockets.emit('post connect',{status: 403});
}
Expand Down
9 changes: 5 additions & 4 deletions views/chat.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
</title>
<link rel="stylesheet" type="text/css" href="/css/chat.css">
<script src="/socket.io/socket.io.js"></script>
</head>
<script>
var myuser = '<%= user.username %>';
var userhash = '<%= user.hash %>';
var rooms = JSON.parse('<%- JSON.stringify(rooms) %>');
var messages = JSON.parse('<%- JSON.stringify(messages) %>');
</script>
<body>
<!-- @todo Feed these values directly to js -->
</head>
<body ng-app="sockchat">
<nav class="navbar has-shadow is-black" id="mainNav" style="position:fixed;z-index:100;width:100%">
<div class="container">
<div class="navbar-brand">
Expand Down Expand Up @@ -106,7 +107,7 @@
<p class="control is-expanded">
<input class="input" id="msgTextBox" type="text" placeholder="<%= user.username %>: Enter Message here">
</p>
<p class="control ">
<p class="control ">
<a id="msgSendBtn" class="button is-primary">
Send
</a>
Expand All @@ -117,7 +118,7 @@
</div>
</div>

<div class="column is-2 messages hero is-fullheight is-black" id="feed-info">
<div class="column is-2 messages hero is-fullheight is-dark" id="feed-info">
<div class="column ">

<div class="panel" id="activeUserpanel">
Expand Down

0 comments on commit a38f0ef

Please sign in to comment.