88 */
99import { 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
2815export 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