Skip to content

Commit 854e4ae

Browse files
SahusoftSahusoft
authored andcommitted
Created Directory Structure [Client-Server] and Fixed Dependencies
1 parent b5cab1d commit 854e4ae

23 files changed

+42
-79
lines changed

app/app.component.js renamed to client/app.component.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ var AppComponent = (function () {
1616
AppComponent = __decorate([
1717
core_1.Component({
1818
selector: 'my-app',
19-
template: "<h1>{{title}}</h1>\n \t\t\t\n\n \t\t\t"
19+
template: "<h1>{{title}}</h1>"
2020
})
2121
], AppComponent);
2222
return AppComponent;
2323
}());
2424
exports.AppComponent = AppComponent;
2525
var socket = io();
26+
//io.connect();
2627
$('form').submit(function () {
2728
socket.emit('chatMessageToSocketServer', $('#message-box').val());
2829
$('#message-box').val('');

app/app.component.ts renamed to client/app.component.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import "http://code.jquery.com/jquery-1.11.1.js";
77

88
@Component({
99
selector: 'my-app',
10-
template: `<h1>{{title}}</h1>
11-
12-
13-
`
10+
template: `<h1>{{title}}</h1>`
1411
})
1512
export class AppComponent {
1613
title = 'Angular 2 Working!';
@@ -25,35 +22,6 @@ export class AppComponent {
2522
socket.on('broadcastToAll_chatMessage', function(msg){
2623
$('#messages').append($('<li>').text(msg));
2724
});
28-
29-
//heroes: Hero[];
30-
// heroes=HEROES;
31-
// selectedHero: Hero;
32-
33-
//constructor(private heroService: HeroService) { }
34-
35-
36-
// getHeroes(): void {
37-
// this.heroService.getHeroes().then(heroes => this.heroes = heroes);
38-
// }
39-
40-
// getHeroes(): void {
41-
// this.heroes = this.heroService.getHeroes();
42-
// }
43-
44-
// ngOnInit(): void {
45-
// this.getHeroes();
46-
// }
47-
48-
49-
// onSelect(hero: Hero): void {
50-
// this.selectedHero = hero;
51-
// }
52-
53-
// hero: Hero = {
54-
// id: 1,
55-
// name: 'Windstorm'
56-
// };
5725
}
5826

5927

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

index.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

index.html renamed to server/index.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<html>
22
<head>
33
<title>Angular2_Node_chatApp</title>
4-
<!-- <style>
5-
/* * { margin: 0; padding: 0; box-sizing: border-box; }*/
6-
</style> -->
74

85
<meta charset="UTF-8">
96
<meta name="viewport" content="width=device-width, initial-scale=1">
@@ -17,12 +14,11 @@
1714

1815
<!-- 2. Configure SystemJS -->
1916
<script src="systemjs.config.js"></script>
20-
2117
<script src="socket.io/socket.io.js"></script>
2218

2319
<script>
24-
System.import('app').catch(function(err){ console.error(err); });
25-
//var socket = io();
20+
//Client Code(Angular2)
21+
System.import('client').catch(function(err){ console.error(err); });
2622
</script>
2723
</head>
2824
<!-- 3. Display the application -->

server/index.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"use strict";
2+
let express = require("express");
3+
var path = require('path');
4+
let chat_app = require('express')();
5+
let http = require('http').Server(chat_app);
6+
let io = require('socket.io')(http);
7+
8+
9+
chat_app.use(express.static(__dirname, '/'));
10+
11+
chat_app.use(express.static(__dirname, '/server/'));
12+
chat_app.use(express.static(__dirname + "/..", '/client/'));
13+
chat_app.use(express.static(__dirname + '/node_modules'));
14+
15+
chat_app.get('/', function(req, res){
16+
res.sendFile(__dirname + '/index.html');
17+
});
18+
19+
io.on('connection', function(socket){
20+
console.log("user connected to socket : ",socket.id);
21+
//console.log('a user connected');
22+
23+
socket.on('disconnect', function(){
24+
console.log('user disconnected');
25+
});
26+
27+
socket.on('chatMessageToSocketServer', function(msg){
28+
console.log('user sent message : '+msg);
29+
io.emit('broadcastToAll_chatMessage', msg);
30+
});
31+
});
32+
33+
http.listen(3000, function(){
34+
console.log('listening on *:3000');
35+
});

0 commit comments

Comments
 (0)