--- /dev/null
+/* Copyright (c) 2019 AT&T Intellectual Property. #\r
+# #\r
+# Licensed under the Apache License, Version 2.0 (the "License"); #\r
+# you may not use this file except in compliance with the License. #\r
+# You may obtain a copy of the License at #\r
+# #\r
+# http://www.apache.org/licenses/LICENSE-2.0 #\r
+# #\r
+# Unless required by applicable law or agreed to in writing, software #\r
+# distributed under the License is distributed on an "AS IS" BASIS, #\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #\r
+# See the License for the specific language governing permissions and #\r
+# limitations under the License. #\r
+##############################################################################*/\r
+\r
+\r
+ \r
+import { Injectable, OnInit } from '@angular/core';\r
+\r
+import * as feathers from '@feathersjs/client';\r
+import * as io from 'socket.io-client';\r
+import * as socketio from '@feathersjs/socketio-client';\r
+import * as authentication from '@feathersjs/authentication-client';\r
+import { Observable, from, interval } from 'rxjs';\r
+import { now } from 'moment';\r
+import { AppGlobals } from 'app/app.global';\r
+import { CookieService } from 'ngx-cookie-service';\r
+import { Router } from '@angular/router';\r
+\r
+\r
+@Injectable({\r
+ providedIn: 'root'\r
+})\r
+export class FeathersService {\r
+ // There are no proper typings available for feathers, due to its plugin-heavy nature\r
+ private _feathers: any;\r
+ public _socket: any;\r
+ public auth: Observable<Object>;\r
+ \r
+ constructor(private route: Router) {\r
+ this._socket = io('/',{\r
+ transports: ['websocket']\r
+ }); // init socket.io\r
+ this._socket.on('connect_error', function(data){\r
+ route.navigateByUrl('/login');\r
+ });\r
+ this._feathers = feathers(); // init Feathers // add hooks plugin\r
+ this._feathers.configure(socketio(this._socket, {\r
+ timeout: 100000000\r
+ })); // add socket.io plugin\r
+ this._feathers.configure(authentication({\r
+ storage: window.localStorage,\r
+ storageKey: 'access_token'\r
+ }));\r
+\r
+ //set observiable for services to check before calling the service\r
+ this.auth = from(this._feathers.authenticate());\r
+ \r
+ }\r
+\r
+ // expose services\r
+ public service(name: string) {\r
+ return this._feathers.service(name);\r
+ }\r
+\r
+ public socket(){\r
+ return this._socket;\r
+ }\r
+\r
+ // expose authentication\r
+ public authenticate(credentials?): Observable<Object> { \r
+ return new Observable(observer => {\r
+ this.auth = from(this._feathers.authenticate(credentials).then(res => {\r
+ observer.next(res);\r
+ }, err => {\r
+ observer.error(err);\r
+ this.route.navigate(['/login'])\r
+ }));\r
+ });\r
+\r
+ }\r
+\r
+ // expose logout\r
+ public logout() {\r
+ return this._feathers.logout();\r
+ }\r
+}\r
+\r