Skip to content

Commit 6ceca90

Browse files
Merge pull request #270 from mean-expert-official/development
2.1.0-rc.6
2 parents aa107d3 + 81405ee commit 6ceca90

25 files changed

+383
-132
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
This file is created to keep history of the LoopBack SDK Builder, it does not consider or keeps any history of its parent module `loopback-sdk-angular`.
44

5+
## Release 2.1.0-rc.6
6+
7+
- Milestone Details: https://github.com/mean-expert-official/loopback-sdk-builder/milestone/28?closed=1
8+
9+
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/268
10+
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/266
11+
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/265
12+
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/264
13+
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/262
14+
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/151
15+
516
## Release 2.1.0-rc.5
617

718
- Milestone Details: https://github.com/mean-expert-official/loopback-sdk-builder/milestone/27?closed=1

lib/angular2/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ module.exports = function generate(ctx) {
147147
* STORAGE
148148
*/
149149
{
150-
template: './shared/storage/internal.storage.ts',
151-
output: '/storage/internal.storage.ts',
150+
template: './shared/storage/storage.swaps.ts',
151+
output: '/storage/storage.swaps.ts',
152152
params: {}
153153
}
154154
];
@@ -159,6 +159,11 @@ module.exports = function generate(ctx) {
159159
output: '/storage/cookie.browser.ts',
160160
params: {}
161161
});
162+
schema.push({
163+
template: './shared/storage/storage.browser.ts',
164+
output: '/storage/storage.browser.ts',
165+
params: {}
166+
});
162167
}
163168
// Add Server Specific Code
164169
if (ctx.driver === 'ng2universal') {
@@ -470,7 +475,7 @@ module.exports = function generate(ctx) {
470475
{ module: 'LoopBackAuth', from: './services/core/auth.service'},
471476
{ module: 'LoggerService', from: './services/custom/logger.service'},
472477
{ module: 'SDKModels', from: './services/custom/SDKModels'},
473-
{ module: 'InternalStorage', from: './storage/internal.storage'},
478+
{ module: 'InternalStorage, SDKStorage', from: './storage/storage.swaps'},
474479
{ module: 'HttpModule', from: '@angular/http'},
475480
{ module: 'CommonModule', from: '@angular/common'},
476481
{ module: 'NgModule, ModuleWithProviders', from: '@angular/core'}
@@ -479,13 +484,15 @@ module.exports = function generate(ctx) {
479484
switch (driver) {
480485
case 'ng2web':
481486
imports.push({ module: 'CookieBrowser', from: './storage/cookie.browser'});
487+
imports.push({ module: 'StorageBrowser', from: './storage/storage.browser'});
482488
if (isIo === 'enabled') {
483489
imports.push({ module: 'SocketBrowser', from: './sockets/socket.browser'});
484490
}
485491
break;
486492
case 'ng2universal':
487493
imports.push({ module: 'CookieBrowser', from: './storage/cookie.browser'});
488494
imports.push({ module: 'CookieNode', from: './storage/cookie.node'});
495+
imports.push({ module: 'StorageBrowser', from: './storage/storage.browser'});
489496
if (isIo === 'enabled') {
490497
imports.push({ module: 'SocketBrowser', from: './sockets/socket.browser'});
491498
imports.push({ module: 'SocketNode', from: './sockets/socket.node'});
@@ -528,6 +535,7 @@ module.exports = function generate(ctx) {
528535
case 'browser':
529536
if (driver === 'ng2web' || driver === 'ng2universal') {
530537
imports.push('{ provide: InternalStorage, useClass: CookieBrowser }');
538+
imports.push('{ provide: SDKStorage, useClass: StorageBrowser }');
531539
if (isIo === 'enabled') {
532540
imports.push('{ provide: SocketDriver, useClass: SocketBrowser }');
533541
}
@@ -544,6 +552,7 @@ module.exports = function generate(ctx) {
544552
case 'nativescript':
545553
if (driver === 'ng2native') {
546554
imports.push('{ provide: InternalStorage, useClass: StorageNative }');
555+
imports.push('{ provide: SDKStorage, useClass: StorageNative }');
547556
if (isIo === 'enabled') {
548557
imports.push('{ provide: SocketDriver, useClass: SocketNative }');
549558
}

lib/angular2/shared/index.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
* // App Root
1919
* import { AppComponent } from './app.component';
2020
* // Feature Modules
21-
* import { SDKModule } from './shared/sdk/sdk.module';
21+
* import { SDK[Browser|Node|Native]Module } from './shared/sdk/sdk.module';
2222
* // Import Routing
2323
* import { routing } from './app.routing';
2424
* @NgModule({
2525
* imports: [
2626
* BrowserModule,
2727
* routing,
28-
* SDKModule.forRoot()
28+
* SDK[Browser|Node|Native]Module.forRoot()
2929
* ],
3030
* declarations: [ AppComponent ],
3131
* bootstrap: [ AppComponent ]

lib/angular2/shared/models/flref.ejs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export class FireLoopRef<T> {
165165
}
166166
sbj.next(data);
167167
};
168-
this.socket.on(nowEvent, pullNow);
168+
this.socket.onZone(nowEvent, pullNow);
169169
return sbj.asObservable();
170170
}
171171
/**
@@ -176,12 +176,12 @@ export class FireLoopRef<T> {
176176
**/
177177
private broadcasts(event: string, request: any): Observable<T> {
178178
let sbj: Subject<T> = new Subject<T>();
179-
this.socket.on(
179+
this.socket.onZone(
180180
`${event}.broadcast.announce.${ this.id }`,
181181
(res: T) =>
182182
this.socket.emit(`${event}.broadcast.request.${ this.id }`, request)
183183
);
184-
this.socket.on(`${ event }.broadcast.${ this.id }`, (data) => sbj.next(data));
184+
this.socket.onZone(`${ event }.broadcast.${ this.id }`, (data) => sbj.next(data));
185185
return sbj.asObservable();
186186
}
187187
/**
@@ -203,7 +203,7 @@ export class FireLoopRef<T> {
203203
parent: this.parent && this.parent.instance ? this.parent.instance : null
204204
};
205205
this.socket.emit(event, config);
206-
this.socket.on(`${ this.model.getModelName() }.value.result.${ this.id }`, (res: any) =>
206+
this.socket.onZone(`${ this.model.getModelName() }.value.result.${ this.id }`, (res: any) =>
207207
subject.next(res.error ? Observable.throw(res.error) : res)
208208
);
209209
return subject.asObservable();

lib/angular2/shared/services/core/auth.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* tslint:disable */
22
declare var Object: any;
33
import { Injectable, Inject } from '@angular/core';
4-
import { InternalStorage } from '../../storage/internal.storage';
4+
import { InternalStorage } from '../../storage/storage.swaps';
55
import { SDKToken, AccessToken } from '../../models/BaseModels';
66

77
/**

lib/angular2/shared/services/core/base.ejs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,16 @@ export abstract class BaseLoopBackApi {
8888
body = postBody;
8989
}
9090
// Separate filter object from url params
91-
let filter: string = '';
9291
if (urlParams.filter) {
93-
filter = `?filter=${ encodeURI(JSON.stringify(urlParams.filter))}`;
92+
headers.append('filter', JSON.stringify(urlParams.filter));
9493
delete urlParams.filter;
9594
}
9695

9796
this.searchParams.setJSON(urlParams);
9897
let request: Request = new Request({
9998
headers : headers,
10099
method : method,
101-
url : `${requestUrl}${filter}`,
100+
url : requestUrl,
102101
search : Object.keys(urlParams).length > 0
103102
? this.searchParams.getURLSearchParams() : null,
104103
body : body ? JSON.stringify(body) : undefined

lib/angular2/shared/services/core/realtime.ejs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ export class RealTime {
2222
@Inject(SDKModels) protected models: SDKModels,
2323
@Inject(LoopBackAuth) protected auth: LoopBackAuth,
2424
@Inject(JSONSearchParams) protected searchParams: JSONSearchParams
25-
) {
26-
this.socket = this.getConnection();
27-
this.IO = new IO(this.socket);
28-
this.FireLoop = new FireLoop(this.socket, models);
25+
) {}
26+
27+
disconnect(): void {
28+
this.connected = false;
29+
this.IO = null;
30+
this.FireLoop = null;
31+
this.connections.disconnect();
2932
}
3033

3134
getConnection(): void {
@@ -41,11 +44,17 @@ export class RealTime {
4144
if (this.connected) {
4245
subject.next();
4346
} else {
47+
this.socket = this.getConnection();
48+
this.IO = new IO(this.socket);
49+
this.FireLoop = new FireLoop(this.socket, this.models);
4450
this.socket.on('connect', () => {
4551
this.connected = true;
4652
subject.next();
4753
});
48-
this.socket.on('disconnect', () => this.connected = false);
54+
this.socket.on('disconnect', () => {
55+
subject.complete();
56+
this.disconnect();
57+
});
4958
}
5059
return subject.asObservable();
5160
}

lib/angular2/shared/sockets/connections.ts

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* tslint:disable */
2-
import { Injectable, Inject } from '@angular/core';
2+
import { Injectable, Inject, NgZone } from '@angular/core';
33
import { SocketDriver } from './socket.driver';
44
import { AccessToken } from '../models';
55
/**
@@ -14,16 +14,25 @@ import { AccessToken } from '../models';
1414
@Injectable()
1515
export class SocketConnections {
1616
private connections: any = {};
17-
private configured: boolean = false;
18-
constructor(@Inject(SocketDriver) private driver: SocketDriver) {}
17+
private configured: boolean = false;
18+
constructor(
19+
@Inject(SocketDriver) private driver: SocketDriver,
20+
@Inject(NgZone) private zone: NgZone
21+
) { }
1922
getHandler(url: string, token: AccessToken) {
23+
console.log('Getting handler for socket connections');
2024
if (!this.connections[url]) {
2125
console.log('Creating a new connection with: ', url);
22-
let config: any = { log: false, secure: false, forceWebsockets: true };
26+
let config: any = { log: false, secure: false, forceNew: true, forceWebsockets: true };
2327
this.connections[url] = this.driver.connect(url, config);
28+
this.connections[url].onZone = ((event: string, handler: Function) => {
29+
this.connections[url].on(event, (data: any) => {
30+
this.zone.run(() => handler(data));
31+
});
32+
});
2433
this.connections[url].on('connect', () => {
25-
if (!this.configured)
26-
this.setupConnection(url, token, config);
34+
if (!this.configured)
35+
this.setupConnection(url, token, config);
2736
});
2837
let forceConfig: any = setInterval(() => {
2938
if (!this.configured && this.connections[url].connected) {
@@ -40,17 +49,35 @@ export class SocketConnections {
4049
return this.connections[url];
4150
}
4251

52+
public disconnect() {
53+
Object.keys(this.connections).forEach((connKey) => {
54+
if (this.connections[connKey].connected) {
55+
this.connections[connKey].disconnect();
56+
}
57+
});
58+
this.connections = {};
59+
this.configured = false;
60+
}
61+
4362
private setupConnection(url: string, token: AccessToken, config: any): void {
4463
this.configured = true;
4564
console.log('Connected to %s', url);
46-
if(token.id) {
65+
if (token.id) {
66+
console.log('Emitting authentication', token.id);
4767
this.connections[url].emit('authentication', token);
4868
}
4969
this.connections[url].on('unauthorized', (res: any) => console.error('Unauthenticated', res));
50-
setInterval(() => this.connections[url].emit('lb-ping'), 15000);
70+
let heartbeater: any = setInterval(() => {
71+
if (this.connections[url]) {
72+
this.connections[url].emit('lb-ping');
73+
} else {
74+
clearInterval(heartbeater);
75+
}
76+
}, 15000);
5177
this.connections[url].on('lb-pong', (data: any) => console.info('Heartbeat: ', data));
5278
this.connections[url].on('disconnect', (data: any) => {
53-
console.info('Unexpected disconnection from IO - Socket IO will try to reconnect');
79+
this.disconnect();
80+
console.info('Disconnected from WebSocket server');
5481
});
5582
}
5683
}

lib/angular2/shared/storage/cookie.browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class CookieBrowser {
2626

2727
set(key: string, value: any, expires?: Date) {
2828
this.cookies[key] = value;
29-
let cookie = `${key}=${value}${expires ? `; expires=${ expires.toUTCString() }` : ''}`;
29+
let cookie = `${key}=${value}; path=/${expires ? `; expires=${ expires.toUTCString() }` : ''}`;
3030
window.document.cookie = cookie;
3131
}
3232

lib/angular2/shared/storage/internal.storage.ts

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

0 commit comments

Comments
 (0)