File tree 2 files changed +9
-6
lines changed
2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ Major and minor versions follow the version number of Twilio javascript SDK. Cur
18
18
19
19
Middleware expects the following dependencies:
20
20
* ** Twilio** : the global Twilio instance
21
- * ** token** : it expects a function that returns a Promise of a capability token
21
+ * ** token** : it expects a function that receives store state and returns a Promise of a capability token
22
22
* ** opts** : Twilio sdk [ options] ( https://www.twilio.com/docs/api/client/device )
23
23
24
24
#### Apply middleware
@@ -29,9 +29,10 @@ import {middleware} from 'twiliojs-redux';
29
29
import fetch from ' isomorphic-fetch' ;
30
30
import rootReducer from ' ./reducers' ;
31
31
32
- const token = () => {
33
- return fetch (' capability_token' )
34
- .then ((response ) => response .text ())
32
+ const token = (state ) => {
33
+ return fetch (' capability_token' , {
34
+ headers: { ' Authorization' : ` Bearer ${ state .authToken } ` }
35
+ }).then ((response ) => response .text ())
35
36
}
36
37
37
38
const createStoreWithMiddleware = applyMiddleware (
Original file line number Diff line number Diff line change @@ -2,14 +2,16 @@ var actions = require('./actions'),
2
2
constants = require ( './constants' ) ;
3
3
4
4
const middleware = ( twilioDevice , token , opts ) => store => {
5
- token ( ) . then ( value => {
5
+ const getToken = ( ) => token ( store . getState ( ) )
6
+
7
+ getToken ( ) . then ( value => {
6
8
twilioDevice . ready ( device => {
7
9
store . dispatch ( actions . changeDeviceStatus ( device ) ) ;
8
10
} ) ;
9
11
10
12
twilioDevice . offline ( device => {
11
13
store . dispatch ( actions . changeDeviceStatus ( device ) ) ;
12
- token ( ) . then ( value => {
14
+ getToken ( ) . then ( value => {
13
15
twilioDevice . setup ( value , opts ) ;
14
16
} )
15
17
} ) ;
You can’t perform that action at this time.
0 commit comments