├── LICENCE
├── README.md
├── app
├── .gitignore
├── app
│ ├── app.core.scss
│ ├── app.html
│ ├── app.ios.scss
│ ├── app.md.scss
│ ├── app.ts
│ ├── app.variables.scss
│ ├── models
│ │ ├── message.ts
│ │ └── user.ts
│ ├── pages
│ │ ├── chat
│ │ │ ├── chat.html
│ │ │ ├── chat.scss
│ │ │ └── chat.ts
│ │ ├── friends
│ │ │ ├── friends.html
│ │ │ ├── friends.scss
│ │ │ └── friends.ts
│ │ └── settings
│ │ │ ├── settings.html
│ │ │ ├── settings.scss
│ │ │ └── settings.ts
│ ├── services
│ │ ├── auth.ts
│ │ └── chat.ts
│ └── utils
│ │ └── utils.ts
├── config.xml
├── hooks
│ ├── README.md
│ └── after_prepare
│ │ └── 010_add_platform_class.js
├── ionic.config.js
├── package.json
├── resources
│ ├── android
│ │ ├── icon
│ │ │ ├── drawable-hdpi-icon.png
│ │ │ ├── drawable-ldpi-icon.png
│ │ │ ├── drawable-mdpi-icon.png
│ │ │ ├── drawable-xhdpi-icon.png
│ │ │ ├── drawable-xxhdpi-icon.png
│ │ │ └── drawable-xxxhdpi-icon.png
│ │ └── splash
│ │ │ ├── drawable-land-hdpi-screen.png
│ │ │ ├── drawable-land-ldpi-screen.png
│ │ │ ├── drawable-land-mdpi-screen.png
│ │ │ ├── drawable-land-xhdpi-screen.png
│ │ │ ├── drawable-land-xxhdpi-screen.png
│ │ │ ├── drawable-land-xxxhdpi-screen.png
│ │ │ ├── drawable-port-hdpi-screen.png
│ │ │ ├── drawable-port-ldpi-screen.png
│ │ │ ├── drawable-port-mdpi-screen.png
│ │ │ ├── drawable-port-xhdpi-screen.png
│ │ │ ├── drawable-port-xxhdpi-screen.png
│ │ │ └── drawable-port-xxxhdpi-screen.png
│ ├── icon.png
│ ├── ios
│ │ ├── icon
│ │ │ ├── icon-40.png
│ │ │ ├── icon-40@2x.png
│ │ │ ├── icon-50.png
│ │ │ ├── icon-50@2x.png
│ │ │ ├── icon-60.png
│ │ │ ├── icon-60@2x.png
│ │ │ ├── icon-60@3x.png
│ │ │ ├── icon-72.png
│ │ │ ├── icon-72@2x.png
│ │ │ ├── icon-76.png
│ │ │ ├── icon-76@2x.png
│ │ │ ├── icon-small.png
│ │ │ ├── icon-small@2x.png
│ │ │ ├── icon-small@3x.png
│ │ │ ├── icon.png
│ │ │ └── icon@2x.png
│ │ └── splash
│ │ │ ├── Default-568h@2x~iphone.png
│ │ │ ├── Default-667h.png
│ │ │ ├── Default-736h.png
│ │ │ ├── Default-Landscape-736h.png
│ │ │ ├── Default-Landscape@2x~ipad.png
│ │ │ ├── Default-Landscape~ipad.png
│ │ │ ├── Default-Portrait@2x~ipad.png
│ │ │ ├── Default-Portrait~ipad.png
│ │ │ ├── Default@2x~iphone.png
│ │ │ └── Default~iphone.png
│ └── splash.png
├── tsconfig.json
├── webpack.config.js
└── www
│ ├── img
│ └── appicon.png
│ └── index.html
├── screenshots
└── screenshot.png
└── server
├── .gitignore
├── config
└── constants.js
├── controllers
└── api.js
├── package.json
├── routes
└── api.js
└── server.js
/LICENCE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Jan Kuri
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ionic2-rxjs-socketio-chat
2 |
3 |
4 | ## Install & Run
5 |
6 | Clone this repo
7 |
8 | ````bash
9 | git clone https://github.com/jkuri/ionic2-rxjs-socketio-chat.git
10 | cd ionic2-rxjs-socketio-chat
11 | ````
12 |
13 | Install server dependencies and run the server.
14 | Note that the server must be running for application to work.
15 |
16 | ````bash
17 | cd server
18 | npm install
19 | node server.js # run the server
20 | ````
21 |
22 | Then install app dependencies.
23 |
24 | ````bash
25 | cd app
26 | npm install
27 | ionic serve # run the app in browser
28 | ````
29 |
30 | Then open another browser and navigate to http://localhost:8100 or emulate app on device.
31 |
32 | Emulate app on iOS (Mac OSX required)
33 | ````bash
34 | ionic platfrom add ios
35 | ionic ios run
36 | ````
37 |
38 | Emulate app on Android
39 | ````bash
40 | ionic platform add android
41 | ionic run android
42 | ````
43 |
44 | ## Author
45 |
46 | [Jan Kuri](http://www.jankuri.com)
47 |
48 | ## Preview
49 | 
50 |
51 | ## Licence
52 |
53 | This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.
54 |
55 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | # Specifies files to intentionally ignore when using Git
2 | # http://git-scm.com/docs/gitignore
3 |
4 | node_modules/
5 | www/build/
6 | platforms/
7 | plugins/
8 | *.swp
9 | .DS_Store
10 | Thumbs.db
11 |
--------------------------------------------------------------------------------
/app/app/app.core.scss:
--------------------------------------------------------------------------------
1 | // http://ionicframework.com/docs/v2/theming/
2 |
3 |
4 | // App Shared Imports
5 | // --------------------------------------------------
6 | // These are the imports which make up the design of this app.
7 | // By default each design mode includes these shared imports.
8 | // App Shared Sass variables belong in app.variables.scss.
9 |
10 | @import "pages/friends/friends";
11 | @import "pages/settings/settings";
12 | @import "pages/chat/chat";
13 |
--------------------------------------------------------------------------------
/app/app/app.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Name
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/app/app.ios.scss:
--------------------------------------------------------------------------------
1 | // http://ionicframework.com/docs/v2/theming/
2 |
3 |
4 | // App Shared Variables
5 | // --------------------------------------------------
6 | // Shared Sass variables go in the app.varialbes.scss file
7 | @import 'app.variables';
8 |
9 |
10 | // App iOS Variables
11 | // --------------------------------------------------
12 | // iOS only Sass variables can go here
13 |
14 |
15 | // Ionic iOS Sass
16 | // --------------------------------------------------
17 | // Custom App variables must be declared before importing Ionic.
18 | // Ionic will use its default values when a custom variable isn't provided.
19 | @import "ionic.ios";
20 |
21 |
22 | // App Shared Sass
23 | // --------------------------------------------------
24 | // All Sass files that make up this app goes into the app.core.scss file.
25 | // For simpler CSS overrides, custom app CSS must come after Ionic's CSS.
26 | @import 'app.core';
27 |
28 |
29 | // App iOS Only Sass
30 | // --------------------------------------------------
31 | // CSS that should only apply to the iOS app
32 |
--------------------------------------------------------------------------------
/app/app/app.md.scss:
--------------------------------------------------------------------------------
1 | // http://ionicframework.com/docs/v2/theming/
2 |
3 |
4 | // App Shared Variables
5 | // --------------------------------------------------
6 | // Shared Sass variables go in the app.varialbes.scss file
7 | @import 'app.variables';
8 |
9 |
10 | // App Material Design Variables
11 | // --------------------------------------------------
12 | // Material Design only Sass variables can go here
13 |
14 |
15 | // Ionic Material Design Sass
16 | // --------------------------------------------------
17 | // Custom App variables must be declared before importing Ionic.
18 | // Ionic will use its default values when a custom variable isn't provided.
19 | @import "ionic.md";
20 |
21 |
22 | // App Shared Sass
23 | // --------------------------------------------------
24 | // All Sass files that make up this app goes into the app.core.scss file.
25 | // For simpler CSS overrides, custom app CSS must come after Ionic's CSS.
26 | @import 'app.core';
27 |
28 |
29 | // App Material Design Only Sass
30 | // --------------------------------------------------
31 | // CSS that should only apply to the Material Design app
32 |
--------------------------------------------------------------------------------
/app/app/app.ts:
--------------------------------------------------------------------------------
1 | import { App, IonicApp, Platform } from 'ionic-framework/ionic';
2 | import { NgIf } from 'angular2/core';
3 | import * as Rx from 'rxjs/Rx';
4 | import { tokenNotExpired } from 'angular2-jwt';
5 | import { User } from './models/user';
6 | import { Message } from './models/message';
7 | import { AuthService } from './services/auth';
8 | import { ChatService } from './services/chat';
9 | import { Friends } from './pages/friends/friends';
10 | import { Settings } from './pages/settings/settings';
11 |
12 | @App({
13 | templateUrl: 'build/app.html',
14 | providers: [AuthService, ChatService]
15 | })
16 |
17 | class ChatApp {
18 | name: string;
19 |
20 | friendsPage: any;
21 | settingsPage: any;
22 | chatPage: any;
23 |
24 | constructor(public app: IonicApp,
25 | public platform: Platform,
26 | public auth: AuthService,
27 | public chat: ChatService) {
28 | this.initializeApp();
29 |
30 | this.friendsPage = Friends;
31 | this.settingsPage = Settings;
32 |
33 | if (tokenNotExpired()) {
34 | this.chat.socketAuth();
35 | }
36 | }
37 |
38 | login(): void {
39 | this.auth.getToken(this.name).then((status) => {
40 | if (status) {
41 | this.chat.socketAuth();
42 | }
43 | });
44 | }
45 |
46 | loggedIn(): boolean {
47 | return tokenNotExpired();
48 | }
49 |
50 | initializeApp(): void {
51 | this.platform.ready().then(() => {
52 |
53 | });
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/app/app.variables.scss:
--------------------------------------------------------------------------------
1 | // http://ionicframework.com/docs/v2/theming/
2 |
3 |
4 | // App Shared Variables
5 | // --------------------------------------------------
6 | // To customize the look and feel of this app, you can override
7 | // the Sass variables found in Ionic's source scss files. Setting
8 | // variables before Ionic's Sass will use these variables rather than
9 | // Ionic's default Sass variable values. App Shared Sass imports belong
10 | // in the app.core.scss file and not this file. Sass variables specific
11 | // to the mode belong in either the app.ios.scss or app.md.scss files.
12 |
13 |
14 | // App Shared Color Variables
15 | // --------------------------------------------------
16 | // It's highly recommended to change the default colors
17 | // to match your app's branding. Ionic uses a Sass map of
18 | // colors so you can add, rename and remove colors as needed.
19 | // The "primary" color is the only required color in the map.
20 | // Both iOS and MD colors can be further customized if colors
21 | // are different per mode.
22 |
23 | $colors: (
24 | primary: #387ef5,
25 | secondary: #32db64,
26 | danger: #f53d3d,
27 | light: #f4f4f4,
28 | dark: #222,
29 | favorite: #69BB7B
30 | );
31 |
--------------------------------------------------------------------------------
/app/app/models/message.ts:
--------------------------------------------------------------------------------
1 | import { User } from './user';
2 | import { Utils } from '../utils/utils';
3 |
4 | let utils: Utils = new Utils();
5 |
6 | export class Message {
7 | id: string;
8 | dateSent: Date;
9 | isRead: boolean;
10 | sender: User;
11 | recipient: User;
12 | msg: string;
13 |
14 | constructor(obj: any) {
15 | this.id = obj.id || utils.randomId();
16 | this.dateSent = new Date();
17 | this.isRead = obj.isRead || false;
18 | this.sender = obj.sender || null;
19 | this.recipient = obj.recipient || null;
20 | this.msg = obj.msg || null;
21 | }
22 |
23 | }
--------------------------------------------------------------------------------
/app/app/models/user.ts:
--------------------------------------------------------------------------------
1 | export class User {
2 | id: string;
3 | name: string;
4 | avatar: string;
5 |
6 | constructor(obj: any) {
7 | this.id = obj.id;
8 | this.name = obj.name;
9 | this.avatar = obj.avatar;
10 | }
11 | }
--------------------------------------------------------------------------------
/app/app/pages/chat/chat.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | {{ friend.name }}
7 |
8 |
9 |
10 |
11 |
12 |
![]()
13 | {{ m.msg }}
14 |
{{ m.dateSent | date:'medium' }}
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
--------------------------------------------------------------------------------
/app/app/pages/chat/chat.scss:
--------------------------------------------------------------------------------
1 | .chat {
2 | padding-bottom: 50px;
3 |
4 | .header {
5 | display: block;
6 | height: 40px;
7 | width: 100%;
8 | padding: 0 5px;
9 | border-bottom: 1px solid #222;
10 | position: fixed;
11 | top: 0;
12 | left: 0;
13 | background: #f4f4f4;
14 | h2 {
15 | font-size: 18px;
16 | padding: 8px 0;
17 | margin: 0;
18 | float: left;
19 | display: block;
20 | }
21 | button {
22 | margin: 6px 0;
23 | float: right;
24 | }
25 | }
26 |
27 | .messages {
28 | width: 100%;
29 | position: absolute;
30 | .message {
31 | width: 70%;
32 | padding: 5px 10px;
33 | background: #387ef5;
34 | color: #fff;
35 | border-radius: 5px;
36 | margin: 5px;
37 | float: left;
38 | .date {
39 | display: block;
40 | font-size: 10px;
41 | }
42 | img.avatar {
43 | width: 30px;
44 | height: 30px;
45 | border-radius: 3px;
46 | display: block;
47 | float: left;
48 | margin-right: 5px;
49 | margin-left: -5px;
50 | }
51 | }
52 | .message.me {
53 | float: right;
54 | background: #fff;
55 | border: 1px solid #387ef5;
56 | color: #222;
57 | text-align: right;
58 | img.avatar {
59 | display: none;
60 | }
61 | }
62 | }
63 |
64 | .msg {
65 | position: fixed;
66 | bottom: 0;
67 | left: 0;
68 | padding: 0 5px;
69 | width: 100%;
70 | height: 40px;
71 | border-top: 1px solid #222;
72 | background: #f4f4f4;
73 | input {
74 | display: block;
75 | float: left;
76 | width: 75%;
77 | outline: none;
78 | border: 1px solid #222;
79 | border-radius: 3px;
80 | padding: 4px 5px;
81 | margin-top: 6px;
82 | }
83 | button {
84 | display: block;
85 | float: right;
86 | width: 18%;
87 | margin-top: 5px;
88 | }
89 | }
90 | }
--------------------------------------------------------------------------------
/app/app/pages/chat/chat.ts:
--------------------------------------------------------------------------------
1 | import { Page, Modal, IonicApp, Events } from 'ionic-framework/ionic';
2 | import { OnInit } from 'angular2/core';
3 | import * as Rx from 'rxjs/Rx';
4 | import { ChatService } from '../../services/chat';
5 | import { Message } from '../../models/message';
6 | import { User } from '../../models/user';
7 |
8 | @Page({
9 | templateUrl: 'build/pages/chat/chat.html'
10 | })
11 |
12 | export class Chat implements OnInit {
13 | msg: string;
14 | msgs: Rx.Subject = new Rx.Subject();
15 | friend: User;
16 | me: User;
17 | content: any;
18 | el: any;
19 |
20 | constructor(public chat: ChatService,
21 | public modal: Modal,
22 | public app: IonicApp,
23 | public e: Events) {
24 | this.me = chat.me;
25 | this.e.subscribe('newMessage', (e) => {
26 | this.scrollTo();
27 | });
28 | }
29 |
30 | ngOnInit(): void {
31 | this.msg = '';
32 |
33 | this.chat.currentFriend
34 | .subscribe((user: User) => {
35 | this.friend = user;
36 | this.msgs = this.chat.getCurrentMessages(this.friend);
37 | });
38 | }
39 |
40 | ngAfterViewInit(): void {
41 | this.content = this.app.getComponent('chat');
42 | this.el = this.content.elementRef.nativeElement;
43 | }
44 |
45 | scrollTo(): void {
46 | // can't get proper this.el.scrollHeight?
47 | this.content.scrollTo(0, 5000000, 200);
48 | }
49 |
50 | sendMessage(): void {
51 | let msg = new Message({
52 | isRead: false,
53 | sender: this.me,
54 | recipient: this.friend,
55 | msg: this.msg
56 | });
57 |
58 | this.chat.sendMessage(msg).then((resp) => {
59 | this.msg = '';
60 | });
61 | }
62 |
63 | public close(): void {
64 | this.modal.close();
65 | }
66 | }
--------------------------------------------------------------------------------
/app/app/pages/friends/friends.html:
--------------------------------------------------------------------------------
1 |
2 | Friends
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | {{ f.name }}
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/app/pages/friends/friends.scss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/app/pages/friends/friends.scss
--------------------------------------------------------------------------------
/app/app/pages/friends/friends.ts:
--------------------------------------------------------------------------------
1 | import { Page, Modal } from 'ionic-framework/ionic';
2 | import * as Rx from 'rxjs/Rx';
3 | import { ChatService } from '../../services/chat';
4 | import { User } from '../../models/user';
5 | import { Chat } from '../chat/chat';
6 |
7 | @Page({
8 | templateUrl: 'build/pages/friends/friends.html'
9 | })
10 |
11 | export class Friends {
12 | public searchQuery: string = '';
13 | friends: Rx.Subject = new Rx.Subject(null);
14 | chatPage: any;
15 |
16 | constructor(public chat: ChatService, public modal: Modal) {
17 | this.friends = chat.friends;
18 | this.chatPage = Chat;
19 | }
20 |
21 | public openChat(user: User): void {
22 | this.chat.setCurrentFriend(user);
23 | this.modal.open(this.chatPage);
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/app/app/pages/settings/settings.html:
--------------------------------------------------------------------------------
1 |
2 | Settings
3 |
4 |
5 |
6 |
7 |
8 |
9 | Logout
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/app/pages/settings/settings.scss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/app/pages/settings/settings.scss
--------------------------------------------------------------------------------
/app/app/pages/settings/settings.ts:
--------------------------------------------------------------------------------
1 | import { Page } from 'ionic-framework/ionic';
2 | import { AuthService } from '../../services/auth';
3 |
4 | @Page({
5 | templateUrl: 'build/pages/settings/settings.html'
6 | })
7 |
8 | export class Settings {
9 |
10 | constructor(public auth: AuthService) { }
11 |
12 | public logout(): void {
13 | this.auth.logout();
14 | }
15 | }
--------------------------------------------------------------------------------
/app/app/services/auth.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from 'angular2/core';
2 | import { Http } from 'angular2/http';
3 | import * as Rx from 'rxjs/Rx';
4 | import { tokenNotExpired, JwtHelper } from 'angular2-jwt';
5 | import 'rxjs/add/operator/map';
6 |
7 | declare var io;
8 |
9 | @Injectable()
10 | export class AuthService {
11 | jwtHelper: JwtHelper;
12 | io: any;
13 |
14 | constructor(public http: Http) {
15 | this.jwtHelper = new JwtHelper();
16 | }
17 |
18 | public getToken(name: string): any {
19 | return new Promise((resolve, reject) => {
20 | this.http.post('http://localhost:3357/api/generate-token', JSON.stringify({ name: name }))
21 | .map(res => res.json())
22 | .subscribe(data => resolve(this.saveToken(data)));
23 | });
24 | }
25 |
26 | private saveToken(data: any): boolean {
27 | if (data.status) {
28 | let decodedToken = this.jwtHelper.decodeToken(data.jwt);
29 | localStorage.setItem('profile', JSON.stringify(decodedToken));
30 | localStorage.setItem('id_token', data.jwt);
31 | return true;
32 | } else {
33 | return false;
34 | }
35 | }
36 |
37 | public logout(): void {
38 | localStorage.removeItem('profile');
39 | localStorage.removeItem('id_token');
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/app/services/chat.ts:
--------------------------------------------------------------------------------
1 | import { Events } from 'ionic-framework/ionic';
2 | import { Injectable } from 'angular2/core';
3 | import * as Rx from 'rxjs/Rx';
4 | import { User } from '../models/user';
5 | import { Message } from '../models/message';
6 |
7 | declare var io;
8 |
9 | @Injectable()
10 | export class ChatService {
11 | socket: any;
12 | me: User;
13 | usersStream: Rx.Observable = Rx.Observable();
14 | usersResponseStream: any;
15 | messagesStream: Rx.Observable = Rx.Observable();
16 | messagesResponseStream: any;
17 | messages: Rx.Subject = new Rx.Subject(null);
18 | currentMessages: Rx.Subject = new Rx.Subject(null);
19 | createMessage: Rx.Subject = new Rx.Subject();
20 | friends: Rx.Subject = new Rx.Subject(null);
21 | currentFriend: Rx.Subject = new Rx.BehaviorSubject(null);
22 |
23 | constructor(public e: Events) { }
24 |
25 | private initUsersStreams(): void {
26 | this.usersStream = Rx.Observable.fromEvent(this.socket, 'onlineUsers');
27 |
28 | this.usersStream.subscribe((users) => {
29 | this.usersResponseStream = Rx.Observable.create((observer) => {
30 | observer.next(users);
31 | });
32 |
33 | this.usersResponseStream.subscribe((users: User[]) => {
34 | this.friends.next(users);
35 | });
36 | });
37 | }
38 |
39 | private initMessagesStreams(): void {
40 | this.messagesStream = Rx.Observable.fromEvent(this.socket, 'onMessage');
41 |
42 | this.messagesStream.subscribe((message: Message) => {
43 | this.messagesResponseStream = Rx.Observable.create((observer) => {
44 | observer.next(message);
45 | });
46 |
47 | this.messagesResponseStream.subscribe((message: Message) => {
48 | this.createMessage.next(message);
49 | });
50 | });
51 |
52 | this.createMessage.map((message: Message) => {
53 | return message;
54 | }).subscribe((message: Message) => {
55 | this.e.publish('newMessage', true);
56 | this.messages.next(message);
57 | });
58 | }
59 |
60 | public setCurrentFriend(user: User): void {
61 | this.currentFriend.next(new User(user));
62 | }
63 |
64 | public getCurrentMessages(user: User): Message[] {
65 | let msgs: Message[] = [];
66 | return this.messages.map((message: Message) => {
67 | if ((message.recipient.id === user.id &&
68 | message.sender.id === this.me.id) ||
69 | (message.recipient.id === this.me.id &&
70 | message.sender.id === user.id)) {
71 | msgs.push(new Message(message));
72 | }
73 | return msgs;
74 | });
75 | }
76 |
77 | public sendMessage(msg: Message): Promise {
78 | return new Promise((resolve, reject) => {
79 | this.socket.emit('sendMessage', msg, (resp) => {
80 | if (resp.status) {
81 | this.addOwnMessage(msg);
82 | resolve();
83 | } else {
84 | reject();
85 | }
86 | });
87 | });
88 | }
89 |
90 | private addOwnMessage(msg: Message): void {
91 | this.createMessage.next(msg);
92 | }
93 |
94 | private initLoggedInUser(): void {
95 | let profileData = JSON.parse(localStorage.getItem('profile'));
96 | if (!profileData) { return; }
97 | this.me = new User({
98 | id: profileData.id,
99 | name: profileData.name,
100 | avatar: profileData.avatar
101 | });
102 | }
103 |
104 | public socketAuth(): void {
105 | let token = localStorage.getItem('id_token');
106 | this.socket = io.connect('http://localhost:3357');
107 | this.socket.on('connect', () => {
108 | this.socket.emit('authenticate', { token: token });
109 | this.initUsersStreams();
110 | this.initMessagesStreams();
111 | this.initLoggedInUser();
112 | });
113 | }
114 |
115 | }
116 |
--------------------------------------------------------------------------------
/app/app/utils/utils.ts:
--------------------------------------------------------------------------------
1 | export class Utils {
2 | public randomId(): number {
3 | return Math.random().toString(36).substring(7);
4 | }
5 | }
--------------------------------------------------------------------------------
/app/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | V2 Test
4 | An Ionic Framework and Cordova project.
5 | Jan Kuri
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/hooks/README.md:
--------------------------------------------------------------------------------
1 |
21 | # Cordova Hooks
22 |
23 | Cordova Hooks represent special scripts which could be added by application and plugin developers or even by your own build system to customize cordova commands. Hook scripts could be defined by adding them to the special predefined folder (`/hooks`) or via configuration files (`config.xml` and `plugin.xml`) and run serially in the following order:
24 | * Application hooks from `/hooks`;
25 | * Application hooks from `config.xml`;
26 | * Plugin hooks from `plugins/.../plugin.xml`.
27 |
28 | __Remember__: Make your scripts executable.
29 |
30 | __Note__: `.cordova/hooks` directory is also supported for backward compatibility, but we don't recommend using it as it is deprecated.
31 |
32 | ## Supported hook types
33 | The following hook types are supported:
34 |
35 | after_build/
36 | after_compile/
37 | after_docs/
38 | after_emulate/
39 | after_platform_add/
40 | after_platform_rm/
41 | after_platform_ls/
42 | after_plugin_add/
43 | after_plugin_ls/
44 | after_plugin_rm/
45 | after_plugin_search/
46 | after_plugin_install/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being installed
47 | after_prepare/
48 | after_run/
49 | after_serve/
50 | before_build/
51 | before_compile/
52 | before_docs/
53 | before_emulate/
54 | before_platform_add/
55 | before_platform_rm/
56 | before_platform_ls/
57 | before_plugin_add/
58 | before_plugin_ls/
59 | before_plugin_rm/
60 | before_plugin_search/
61 | before_plugin_install/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being installed
62 | before_plugin_uninstall/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being uninstalled
63 | before_prepare/
64 | before_run/
65 | before_serve/
66 | pre_package/ <-- Windows 8 and Windows Phone only.
67 |
68 | ## Ways to define hooks
69 | ### Via '/hooks' directory
70 | To execute custom action when corresponding hook type is fired, use hook type as a name for a subfolder inside 'hooks' directory and place you script file here, for example:
71 |
72 | # script file will be automatically executed after each build
73 | hooks/after_build/after_build_custom_action.js
74 |
75 |
76 | ### Config.xml
77 |
78 | Hooks can be defined in project's `config.xml` using `` elements, for example:
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 | ...
89 |
90 |
91 |
92 |
93 |
94 |
95 | ...
96 |
97 |
98 | ### Plugin hooks (plugin.xml)
99 |
100 | As a plugin developer you can define hook scripts using `` elements in a `plugin.xml` like that:
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 | ...
109 |
110 |
111 | `before_plugin_install`, `after_plugin_install`, `before_plugin_uninstall` plugin hooks will be fired exclusively for the plugin being installed/uninstalled.
112 |
113 | ## Script Interface
114 |
115 | ### Javascript
116 |
117 | If you are writing hooks in Javascript you should use the following module definition:
118 | ```javascript
119 | module.exports = function(context) {
120 | ...
121 | }
122 | ```
123 |
124 | You can make your scipts async using Q:
125 | ```javascript
126 | module.exports = function(context) {
127 | var Q = context.requireCordovaModule('q');
128 | var deferral = new Q.defer();
129 |
130 | setTimeout(function(){
131 | console.log('hook.js>> end');
132 | deferral.resolve();
133 | }, 1000);
134 |
135 | return deferral.promise;
136 | }
137 | ```
138 |
139 | `context` object contains hook type, executed script full path, hook options, command-line arguments passed to Cordova and top-level "cordova" object:
140 | ```json
141 | {
142 | "hook": "before_plugin_install",
143 | "scriptLocation": "c:\\script\\full\\path\\appBeforePluginInstall.js",
144 | "cmdLine": "The\\exact\\command\\cordova\\run\\with arguments",
145 | "opts": {
146 | "projectRoot":"C:\\path\\to\\the\\project",
147 | "cordova": {
148 | "platforms": ["wp8"],
149 | "plugins": ["com.plugin.withhooks"],
150 | "version": "0.21.7-dev"
151 | },
152 | "plugin": {
153 | "id": "com.plugin.withhooks",
154 | "pluginInfo": {
155 | ...
156 | },
157 | "platform": "wp8",
158 | "dir": "C:\\path\\to\\the\\project\\plugins\\com.plugin.withhooks"
159 | }
160 | },
161 | "cordova": {...}
162 | }
163 |
164 | ```
165 | `context.opts.plugin` object will only be passed to plugin hooks scripts.
166 |
167 | You can also require additional Cordova modules in your script using `context.requireCordovaModule` in the following way:
168 | ```javascript
169 | var Q = context.requireCordovaModule('q');
170 | ```
171 |
172 | __Note__: new module loader script interface is used for the `.js` files defined via `config.xml` or `plugin.xml` only.
173 | For compatibility reasons hook files specified via `/hooks` folders are run via Node child_process spawn, see 'Non-javascript' section below.
174 |
175 | ### Non-javascript
176 |
177 | Non-javascript scripts are run via Node child_process spawn from the project's root directory and have the root directory passes as the first argument. All other options are passed to the script using environment variables:
178 |
179 | * CORDOVA_VERSION - The version of the Cordova-CLI.
180 | * CORDOVA_PLATFORMS - Comma separated list of platforms that the command applies to (e.g.: android, ios).
181 | * CORDOVA_PLUGINS - Comma separated list of plugin IDs that the command applies to (e.g.: org.apache.cordova.file, org.apache.cordova.file-transfer)
182 | * CORDOVA_HOOK - Path to the hook that is being executed.
183 | * CORDOVA_CMDLINE - The exact command-line arguments passed to cordova (e.g.: cordova run ios --emulate)
184 |
185 | If a script returns a non-zero exit code, then the parent cordova command will be aborted.
186 |
187 | ## Writing hooks
188 |
189 | We highly recommend writing your hooks using Node.js so that they are
190 | cross-platform. Some good examples are shown here:
191 |
192 | [http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/](http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/)
193 |
194 | Also, note that even if you are working on Windows, and in case your hook scripts aren't bat files (which is recommended, if you want your scripts to work in non-Windows operating systems) Cordova CLI will expect a shebang line as the first line for it to know the interpreter it needs to use to launch the script. The shebang line should match the following example:
195 |
196 | #!/usr/bin/env [name_of_interpreter_executable]
197 |
--------------------------------------------------------------------------------
/app/hooks/after_prepare/010_add_platform_class.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | // Add Platform Class
4 | // v1.0
5 | // Automatically adds the platform class to the body tag
6 | // after the `prepare` command. By placing the platform CSS classes
7 | // directly in the HTML built for the platform, it speeds up
8 | // rendering the correct layout/style for the specific platform
9 | // instead of waiting for the JS to figure out the correct classes.
10 |
11 | var fs = require('fs');
12 | var path = require('path');
13 |
14 | var rootdir = process.argv[2];
15 |
16 | function addPlatformBodyTag(indexPath, platform) {
17 | // add the platform class to the body tag
18 | try {
19 | var platformClass = 'platform-' + platform;
20 | var cordovaClass = 'platform-cordova platform-webview';
21 |
22 | var html = fs.readFileSync(indexPath, 'utf8');
23 |
24 | var bodyTag = findBodyTag(html);
25 | if(!bodyTag) return; // no opening body tag, something's wrong
26 |
27 | if(bodyTag.indexOf(platformClass) > -1) return; // already added
28 |
29 | var newBodyTag = bodyTag;
30 |
31 | var classAttr = findClassAttr(bodyTag);
32 | if(classAttr) {
33 | // body tag has existing class attribute, add the classname
34 | var endingQuote = classAttr.substring(classAttr.length-1);
35 | var newClassAttr = classAttr.substring(0, classAttr.length-1);
36 | newClassAttr += ' ' + platformClass + ' ' + cordovaClass + endingQuote;
37 | newBodyTag = bodyTag.replace(classAttr, newClassAttr);
38 |
39 | } else {
40 | // add class attribute to the body tag
41 | newBodyTag = bodyTag.replace('>', ' class="' + platformClass + ' ' + cordovaClass + '">');
42 | }
43 |
44 | html = html.replace(bodyTag, newBodyTag);
45 |
46 | fs.writeFileSync(indexPath, html, 'utf8');
47 |
48 | process.stdout.write('add to body class: ' + platformClass + '\n');
49 | } catch(e) {
50 | process.stdout.write(e);
51 | }
52 | }
53 |
54 | function findBodyTag(html) {
55 | // get the body tag
56 | try{
57 | return html.match(/])(.*?)>/gi)[0];
58 | }catch(e){}
59 | }
60 |
61 | function findClassAttr(bodyTag) {
62 | // get the body tag's class attribute
63 | try{
64 | return bodyTag.match(/ class=["|'](.*?)["|']/gi)[0];
65 | }catch(e){}
66 | }
67 |
68 | if (rootdir) {
69 |
70 | // go through each of the platform directories that have been prepared
71 | var platforms = (process.env.CORDOVA_PLATFORMS ? process.env.CORDOVA_PLATFORMS.split(',') : []);
72 |
73 | for(var x=0; x= 7',
33 | 'Android >= 4',
34 | 'Explorer >= 10',
35 | 'ExplorerMobile >= 11'
36 | ],
37 | cascade: false
38 | },
39 |
40 | // hooks execute before or after all project-related Ionic commands
41 | // (so not for start, docs, but serve, run, etc.) and take in the arguments
42 | // passed to the command as a parameter
43 | //
44 | // The format is 'before' or 'after' + commandName (uppercased)
45 | // ex: beforeServe, afterRun, beforePrepare, etc.
46 | hooks: {
47 | beforeServe: function(argv) {
48 | //console.log('beforeServe');
49 | }
50 | }
51 | };
52 |
--------------------------------------------------------------------------------
/app/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "angular2": "2.0.0-beta.0",
4 | "angular2-jwt": "^0.1.3",
5 | "es6-promise": "3.0.2",
6 | "es6-shim": "0.33.13",
7 | "ionic-framework": "2.0.0-alpha.45",
8 | "reflect-metadata": "0.1.2",
9 | "rxjs": "5.0.0-beta.0",
10 | "zone.js": "0.5.10"
11 | },
12 | "devDependencies": {
13 | "awesome-typescript-loader": "^0.15.9",
14 | "strip-sourcemap-loader": "0.0.1",
15 | "typescript": "^1.7.3"
16 | },
17 | "name": "app",
18 | "description": "app: An Ionic project",
19 | "cordovaPlugins": [
20 | "cordova-plugin-device",
21 | "cordova-plugin-console",
22 | "cordova-plugin-whitelist",
23 | "cordova-plugin-splashscreen",
24 | "cordova-plugin-statusbar",
25 | "ionic-plugin-keyboard"
26 | ],
27 | "cordovaPlatforms": []
28 | }
29 |
--------------------------------------------------------------------------------
/app/resources/android/icon/drawable-hdpi-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/icon/drawable-hdpi-icon.png
--------------------------------------------------------------------------------
/app/resources/android/icon/drawable-ldpi-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/icon/drawable-ldpi-icon.png
--------------------------------------------------------------------------------
/app/resources/android/icon/drawable-mdpi-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/icon/drawable-mdpi-icon.png
--------------------------------------------------------------------------------
/app/resources/android/icon/drawable-xhdpi-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/icon/drawable-xhdpi-icon.png
--------------------------------------------------------------------------------
/app/resources/android/icon/drawable-xxhdpi-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/icon/drawable-xxhdpi-icon.png
--------------------------------------------------------------------------------
/app/resources/android/icon/drawable-xxxhdpi-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/icon/drawable-xxxhdpi-icon.png
--------------------------------------------------------------------------------
/app/resources/android/splash/drawable-land-hdpi-screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/splash/drawable-land-hdpi-screen.png
--------------------------------------------------------------------------------
/app/resources/android/splash/drawable-land-ldpi-screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/splash/drawable-land-ldpi-screen.png
--------------------------------------------------------------------------------
/app/resources/android/splash/drawable-land-mdpi-screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/splash/drawable-land-mdpi-screen.png
--------------------------------------------------------------------------------
/app/resources/android/splash/drawable-land-xhdpi-screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/splash/drawable-land-xhdpi-screen.png
--------------------------------------------------------------------------------
/app/resources/android/splash/drawable-land-xxhdpi-screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/splash/drawable-land-xxhdpi-screen.png
--------------------------------------------------------------------------------
/app/resources/android/splash/drawable-land-xxxhdpi-screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/splash/drawable-land-xxxhdpi-screen.png
--------------------------------------------------------------------------------
/app/resources/android/splash/drawable-port-hdpi-screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/splash/drawable-port-hdpi-screen.png
--------------------------------------------------------------------------------
/app/resources/android/splash/drawable-port-ldpi-screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/splash/drawable-port-ldpi-screen.png
--------------------------------------------------------------------------------
/app/resources/android/splash/drawable-port-mdpi-screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/splash/drawable-port-mdpi-screen.png
--------------------------------------------------------------------------------
/app/resources/android/splash/drawable-port-xhdpi-screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/splash/drawable-port-xhdpi-screen.png
--------------------------------------------------------------------------------
/app/resources/android/splash/drawable-port-xxhdpi-screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/splash/drawable-port-xxhdpi-screen.png
--------------------------------------------------------------------------------
/app/resources/android/splash/drawable-port-xxxhdpi-screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/android/splash/drawable-port-xxxhdpi-screen.png
--------------------------------------------------------------------------------
/app/resources/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/icon.png
--------------------------------------------------------------------------------
/app/resources/ios/icon/icon-40.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/icon/icon-40.png
--------------------------------------------------------------------------------
/app/resources/ios/icon/icon-40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/icon/icon-40@2x.png
--------------------------------------------------------------------------------
/app/resources/ios/icon/icon-50.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/icon/icon-50.png
--------------------------------------------------------------------------------
/app/resources/ios/icon/icon-50@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/icon/icon-50@2x.png
--------------------------------------------------------------------------------
/app/resources/ios/icon/icon-60.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/icon/icon-60.png
--------------------------------------------------------------------------------
/app/resources/ios/icon/icon-60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/icon/icon-60@2x.png
--------------------------------------------------------------------------------
/app/resources/ios/icon/icon-60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/icon/icon-60@3x.png
--------------------------------------------------------------------------------
/app/resources/ios/icon/icon-72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/icon/icon-72.png
--------------------------------------------------------------------------------
/app/resources/ios/icon/icon-72@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/icon/icon-72@2x.png
--------------------------------------------------------------------------------
/app/resources/ios/icon/icon-76.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/icon/icon-76.png
--------------------------------------------------------------------------------
/app/resources/ios/icon/icon-76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/icon/icon-76@2x.png
--------------------------------------------------------------------------------
/app/resources/ios/icon/icon-small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/icon/icon-small.png
--------------------------------------------------------------------------------
/app/resources/ios/icon/icon-small@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/icon/icon-small@2x.png
--------------------------------------------------------------------------------
/app/resources/ios/icon/icon-small@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/icon/icon-small@3x.png
--------------------------------------------------------------------------------
/app/resources/ios/icon/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/icon/icon.png
--------------------------------------------------------------------------------
/app/resources/ios/icon/icon@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/icon/icon@2x.png
--------------------------------------------------------------------------------
/app/resources/ios/splash/Default-568h@2x~iphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/splash/Default-568h@2x~iphone.png
--------------------------------------------------------------------------------
/app/resources/ios/splash/Default-667h.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/splash/Default-667h.png
--------------------------------------------------------------------------------
/app/resources/ios/splash/Default-736h.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/splash/Default-736h.png
--------------------------------------------------------------------------------
/app/resources/ios/splash/Default-Landscape-736h.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/splash/Default-Landscape-736h.png
--------------------------------------------------------------------------------
/app/resources/ios/splash/Default-Landscape@2x~ipad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/splash/Default-Landscape@2x~ipad.png
--------------------------------------------------------------------------------
/app/resources/ios/splash/Default-Landscape~ipad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/splash/Default-Landscape~ipad.png
--------------------------------------------------------------------------------
/app/resources/ios/splash/Default-Portrait@2x~ipad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/splash/Default-Portrait@2x~ipad.png
--------------------------------------------------------------------------------
/app/resources/ios/splash/Default-Portrait~ipad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/splash/Default-Portrait~ipad.png
--------------------------------------------------------------------------------
/app/resources/ios/splash/Default@2x~iphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/splash/Default@2x~iphone.png
--------------------------------------------------------------------------------
/app/resources/ios/splash/Default~iphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/ios/splash/Default~iphone.png
--------------------------------------------------------------------------------
/app/resources/splash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/resources/splash.png
--------------------------------------------------------------------------------
/app/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES5",
4 | "module": "commonjs",
5 | "noEmitOnError": false,
6 | "rootDir": ".",
7 | "emitDecoratorMetadata": true,
8 | "experimentalDecorators": true,
9 | "sourceMap": false,
10 | "sourceRoot": "",
11 | "inlineSourceMap": false,
12 | "inlineSources": false
13 | },
14 | "files": [
15 | "app/app.ts"
16 | ],
17 | "exclude": [
18 | "node_modules"
19 | ],
20 | "compileOnSave": false
21 | }
22 |
--------------------------------------------------------------------------------
/app/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 |
3 |
4 | module.exports = {
5 | entry: [
6 | path.normalize('es6-shim/es6-shim.min'),
7 | 'reflect-metadata',
8 | 'web-animations.min',
9 | path.normalize('zone.js/dist/zone-microtask'),
10 | path.resolve('app/app')
11 | ],
12 | output: {
13 | path: path.resolve('www/build/js'),
14 | filename: 'app.bundle.js',
15 | pathinfo: false // show module paths in the bundle, handy for debugging
16 | },
17 | module: {
18 | loaders: [
19 | {
20 | test: /\.ts$/,
21 | loader: 'awesome-typescript',
22 | query: {
23 | 'doTypeCheck': false
24 | },
25 | include: path.resolve('app'),
26 | exclude: /node_modules/
27 | },
28 | {
29 | test: /\.js$/,
30 | include: path.resolve('node_modules/angular2'),
31 | loader: 'strip-sourcemap'
32 | }
33 | ],
34 | noParse: [
35 | /es6-shim/,
36 | /reflect-metadata/,
37 | /web-animations/,
38 | /zone\.js(\/|\\)dist(\/|\\)zone-microtask/
39 | ]
40 | },
41 | resolve: {
42 | alias: {
43 | 'web-animations.min': path.normalize('ionic-framework/js/web-animations.min')
44 | },
45 | extensions: ["", ".js", ".ts"]
46 | }
47 | };
48 |
--------------------------------------------------------------------------------
/app/www/img/appicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/app/www/img/appicon.png
--------------------------------------------------------------------------------
/app/www/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Ionic
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/screenshots/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jkuri/ionic2-rxjs-socketio-chat/34417560fcbde7c452b8265494093f302b6e9e10/screenshots/screenshot.png
--------------------------------------------------------------------------------
/server/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
--------------------------------------------------------------------------------
/server/config/constants.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 | secret: 'Ionic2ChatAppSecretToken!!'
5 | };
--------------------------------------------------------------------------------
/server/controllers/api.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const jwt = require('jsonwebtoken');
4 | const config = require('../config/constants');
5 |
6 | function createToken(user) {
7 | return jwt.sign(user, config.secret);
8 | }
9 |
10 | function generateRandomId() {
11 | return Math.random().toString(36).substring(7);
12 | }
13 |
14 | function generateRandomAvatar() {
15 | let genders = ['men', 'women'];
16 | let g = genders[Math.floor(Math.random() * 2)];
17 | let num = Math.floor(Math.random() * 50) + 1;
18 | return 'http://api.randomuser.me/portraits/thumb/' + g + '/' + num + '.jpg';
19 | }
20 |
21 | exports.generateToken = {
22 | handler: (request, reply) => {
23 | let data = JSON.parse(request.payload);
24 | if (!data.name) {
25 | return reply({status: false});
26 | } else {
27 | let user = {
28 | id: generateRandomId(),
29 | name: data.name,
30 | avatar: generateRandomAvatar()
31 | };
32 | return reply({status: true, jwt: createToken(user)});
33 | }
34 | }
35 | };
--------------------------------------------------------------------------------
/server/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ionic2-chat-app-socket-io-server",
3 | "version": "0.2.0",
4 | "description": "Ionic2 Demo Chat App Socket.IO Server ",
5 | "main": "server.js",
6 | "author": "Jan Kuri ",
7 | "license": "MIT",
8 | "dependencies": {
9 | "chalk": "^1.1.1",
10 | "hapi": "^11.1.3",
11 | "jsonwebtoken": "^5.4.1",
12 | "lodash": "^3.10.1",
13 | "socket.io": "^1.3.7",
14 | "socketio-jwt": "^4.3.3"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/server/routes/api.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const Api = require('../controllers/api');
4 |
5 | module.exports = [
6 | { method: 'POST', path: '/api/generate-token', config: Api.generateToken }
7 | ];
--------------------------------------------------------------------------------
/server/server.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const Hapi = require('Hapi');
4 | const server = new Hapi.Server();
5 | const port = 3357;
6 | server.connection({ port: port, routes: { cors: true } });
7 |
8 | const io = require('socket.io')(server.listener);
9 | const SocketIoJwt = require('socketio-jwt');
10 | const _ = require('lodash');
11 | const chalk = require('chalk');
12 | let connections = [];
13 |
14 | server.route(require('./routes/api'));
15 |
16 | io.sockets.on('connection', SocketIoJwt.authorize({
17 | secret: 'Ionic2ChatAppSecretToken!!',
18 | timeout: 15000
19 | })).on('authenticated', (socket) => {
20 | socket.id = socket.decoded_token.id;
21 | socket.name = socket.decoded_token.name;
22 | socket.avatar = socket.decoded_token.avatar;
23 | connections.push(socket);
24 | console.log(chalk.green('User', socket.name, '(' + socket.id + ') connected.'));
25 |
26 | emitOnlineUsers();
27 |
28 | socket.on('disconnect', () => {
29 | console.log(chalk.red('User', socket.name, '(' + socket.id + ') disconnected'));
30 | connections.splice(connections.indexOf(socket), 1);
31 | emitOnlineUsers();
32 | });
33 |
34 | socket.on('sendMessage', (msg, cb) => {
35 | let index = _.findIndex(connections, (c) => { return c.id === msg.recipient.id });
36 | connections[index].emit('onMessage', msg);
37 | return cb({status: true});
38 | });
39 |
40 | function emitOnlineUsers() {
41 | connections.forEach((socket) => {
42 | socket.emit('onlineUsers', onlineUsers(socket));
43 | });
44 | }
45 |
46 | function onlineUsers(socket) {
47 | let friends = connections.slice();
48 | friends = _.remove(friends, (friend) => {
49 | return friend.id !== socket.id;
50 | });
51 | return _.map(friends, (obj) => { return _.pick(obj, 'id', 'name', 'avatar'); });
52 | }
53 |
54 | });
55 |
56 | server.start(() => {
57 | console.log(chalk.green('Server running at port', port));
58 | });
59 |
--------------------------------------------------------------------------------