Get the remote api port from the url

This commit is contained in:
Simon Hanna 2018-08-27 23:01:02 +02:00
parent e7325c674b
commit db7e4ec1a0

View File

@ -2,10 +2,10 @@ import { Injectable, EventEmitter } from '@angular/core';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { URLSearchParams, Http } from '@angular/http'; import { URLSearchParams, Http } from '@angular/http';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { map, take } from 'rxjs/operators'; import { map, take } from 'rxjs/operators';
import { PluginDescription, State, Slide, ServiceItem } from './responses'; import { PluginDescription, State, Slide, ServiceItem } from './responses';
import { environment } from '../environments/environment';
let deserialize = (json, cls) => { let deserialize = (json, cls) => {
var inst = new cls(); var inst = new cls();
@ -20,11 +20,19 @@ let deserialize = (json, cls) => {
@Injectable() @Injectable()
export class OpenLPService { export class OpenLPService {
private apiURL: string = 'http://localhost:4316'; private apiURL: string;
public stateChanged$: EventEmitter<State>; public stateChanged$: EventEmitter<State>;
constructor(private http: HttpClient) { constructor(private http: HttpClient) {
let port: string;
if (environment.production) {
port = window.location.port;
} else {
port = '4316';
}
this.apiURL = `http://localhost:${port}`;
this.stateChanged$ = new EventEmitter<State>(); this.stateChanged$ = new EventEmitter<State>();
let state:State = null; let state:State = null;
let ws:WebSocket = new WebSocket('ws://localhost:4317/state') let ws:WebSocket = new WebSocket('ws://localhost:4317/state')