Skip to content

Commit bc16328

Browse files
fix(subscriptions):Improve SSR support (#137)
Add copy of paho-client to vendor folder
1 parent 57ac50c commit bc16328

File tree

4 files changed

+2402
-155
lines changed

4 files changed

+2402
-155
lines changed

packages/aws-appsync/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"apollo-link-http": "^1.0.0",
2626
"aws-sdk": "^2.139.0",
2727
"graphql": "^0.11.7",
28-
"paho-client": "^1.0.1",
2928
"redux": "^3.7.2",
3029
"redux-thunk": "^2.2.0",
3130
"setimmediate": "^1.0.5",

packages/aws-appsync/src/link/subscription-handshake-link.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,9 @@
88
*/
99
import { ApolloLink, Observable } from "apollo-link";
1010

11-
import * as Paho from 'paho-client/src/mqttws31';
11+
import * as Paho from '../vendor/paho-mqtt';
1212

13-
const { MQTT: { Client } } = Paho;
14-
15-
// super simple in-memory implementation of localStorage. Needed by Paho client on react-native
16-
if (!window.localStorage) {
17-
window.localStorage = (() => {
18-
const data = {}
19-
20-
return {
21-
setItem: (key, item) => data[key] = item,
22-
getItem: (key) => data[key],
23-
removeItem: (key) => delete data[key],
24-
};
25-
})();
26-
}
13+
const { Client } = Paho;
2714

2815
export class SubscriptionHandshakeLink extends ApolloLink {
2916

@@ -33,7 +20,7 @@ export class SubscriptionHandshakeLink extends ApolloLink {
3320
subsInfoContextKey;
3421

3522
/**
36-
* @type {Map<Paho.MQTT.Client, [string]>}
23+
* @type {Map<Paho.Client, [string]>}
3724
*/
3825
clientTopics = new Map();
3926

@@ -50,8 +37,8 @@ export class SubscriptionHandshakeLink extends ApolloLink {
5037
request = (operation) => {
5138
const { [this.subsInfoContextKey]: subsInfo } = operation.getContext();
5239
const {
53-
extensions: {
54-
subscription: { newSubscriptions, mqttConnections }
40+
extensions: {
41+
subscription: { newSubscriptions, mqttConnections }
5542
}
5643
} = subsInfo;
5744

@@ -132,7 +119,7 @@ export class SubscriptionHandshakeLink extends ApolloLink {
132119

133120
/**
134121
*
135-
* @param {Paho.MQTT.Client} client
122+
* @param {Paho.Client} client
136123
* @param {Set<string>} topics
137124
*/
138125
disconnectClient = (client, topics) => {
@@ -173,7 +160,7 @@ export class SubscriptionHandshakeLink extends ApolloLink {
173160
connect = (observer, lastTopicObserver, connectionInfo) => {
174161
const { topics, client: clientId, url } = connectionInfo;
175162

176-
const client = new Paho.MQTT.Client(url, clientId);
163+
const client = new Paho.Client(url, clientId);
177164
// client.trace = console.log.bind(null, clientId);
178165

179166
client.onMessageArrived = ({ destinationName, payloadString }) => this.onMessage(destinationName, payloadString);

0 commit comments

Comments
 (0)