Skip to content

Commit

Permalink
Merge branch 'master' of github.com:digitallyinduced/ihp
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Dec 22, 2021
2 parents 31c432c + 33e86d5 commit a16a6d2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/IHP/DataSync/ihp-datasync-react.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react';
import { DataSubscription } from './ihp-datasync';
import { DataSubscription } from './ihp-datasync.js';

// Usage:
//
Expand Down
14 changes: 7 additions & 7 deletions lib/IHP/DataSync/ihp-datasync.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
class DataSyncController {
static getInstance() {
if (!window.dataSyncController) {
window.dataSyncController = new DataSyncController();
if (!DataSyncController.instance) {
DataSyncController.instance = new DataSyncController();
}

return window.dataSyncController;
return DataSyncController.instance;
}

static getWSUrl() {
if (window.ihpBackendHost) {
if (DataSyncController.ihpBackendHost) {
const jwt = localStorage.getItem('ihp_jwt');
const host = window.ihpBackendHost
const host = DataSyncController.ihpBackendHost
.replace('https://', 'wss://')
.replace('http://', 'ws://')
return host + '/DataSyncController' + (jwt !== null ? '?access_token=' + encodeURIComponent(jwt) : '');
}

var socketProtocol = location.protocol === 'https:' ? 'wss' : 'ws';
var socketHost = socketProtocol + "://" + window.location.hostname + ":" + document.location.port + '/DataSyncController';
var socketHost = socketProtocol + "://" + document.location.hostname + ":" + document.location.port + '/DataSyncController';
return socketHost;
}

Expand Down Expand Up @@ -212,7 +212,7 @@ function initIHPBackend({ host }) {
if (host.endsWith('/')) {
throw new Error('IHP Backend host url should not have a trailing slash, please remove the last \"/\" from \"' + host + "\"")
}
window.ihpBackendHost = host;
DataSyncController.ihpBackendHost = host;
}

export async function createRecord(table, record) {
Expand Down
4 changes: 2 additions & 2 deletions lib/IHP/DataSync/ihp-querybuilder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataSyncController } from 'ihp-datasync/ihp-datasync';
import { DataSyncController } from './ihp-datasync.js';

function fetchAuthenticated(path, params) {
const jwt = localStorage.getItem('ihp_jwt');
Expand All @@ -12,7 +12,7 @@ function fetchAuthenticated(path, params) {
}

function ihpBackendUrl(path) {
const host = window.ihpBackendHost || '';
const host = DataSyncController.ihpBackendHost || '';
return host + path;
}

Expand Down

0 comments on commit a16a6d2

Please sign in to comment.