Skip to content
This repository was archived by the owner on Jun 28, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions lib/falcor-http-ws-datasource.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SocketIoClient from 'socket.io-client';
import FalcorHttpDataSource from '@synhaptein/falcor-http-datasource';
import FalcorHttpDataSource from 'falcor-http-datasource';
import Uuid from 'uuid';
import DelayedFunction from './delayed-function';
import Q from 'q';
Expand Down Expand Up @@ -51,11 +51,6 @@ class FalcorHttpPullWebSocketPushDataSource extends FalcorHttpDataSource {

config.headers[config.tabIdLabel || 'X-TabId'] = tabId;

if (!config.bearerToken && config.headers['Authorization']) {
let tokens = config.headers.Authorization.split(' ');
config.bearerToken = tokens[1];
}

let socket = null;
if (pushUrl && pushUrl.length > 0) {
let wsUrlPath = pushUrl.match(/(ws+:\/\/[A-Za-z0-9\-\.]*:?[0-9]*)(\/?.*)/);
Expand All @@ -75,9 +70,9 @@ class FalcorHttpPullWebSocketPushDataSource extends FalcorHttpDataSource {
this.requestWatcher = new DelayedFunction(200); // Delay maxium between 2 falcor requests
}

_readBearerTokenFromDynamicHeaders() {
if (this.config.dynamicHeaders) {
let tokens = this.config.dynamicHeaders ? this.config.dynamicHeaders()['Authorization'].split(' ') : null;
_readBearerTokenFromHeaders() {
if (!this.config.bearerToken && this.config.headers.Authorization) {
let tokens = this.config.headers.Authorization.split(' ');
this.config.bearerToken = tokens[1];
}

Expand All @@ -96,7 +91,7 @@ class FalcorHttpPullWebSocketPushDataSource extends FalcorHttpDataSource {
this.socket = new SocketIoClient(this.pushUrl, this.config);

this.socket.on('connect', () => {
this.socket.emit('authorization', {bearerToken: this._readBearerTokenFromDynamicHeaders(), tabId: this.tabId});
this.socket.emit('authorization', {bearerToken: this._readBearerTokenFromHeaders(), tabId: this.tabId});
});

if (this.callback) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "falcor-http-ws-datasource",
"version": "0.2.2",
"version": "1.0.0",
"description": "Falcor HTTP and WebSocket datasource",
"homepage": "",
"author": {
Expand All @@ -16,7 +16,7 @@
""
],
"dependencies": {
"@synhaptein/falcor-http-datasource": "0.1.6",
"falcor-http-datasource": "0.1.3",
"q": "1.4.1",
"socket.io-client": "1.5.0",
"uuid": "2.0.1"
Expand Down