File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Expand file tree Collapse file tree 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
1818
1919Middleware expects the following dependencies:
2020* ** 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
2222* ** opts** : Twilio sdk [ options] ( https://www.twilio.com/docs/api/client/device )
2323
2424#### Apply middleware
@@ -29,9 +29,10 @@ import {middleware} from 'twiliojs-redux';
2929import fetch from ' isomorphic-fetch' ;
3030import rootReducer from ' ./reducers' ;
3131
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 ())
3536}
3637
3738const createStoreWithMiddleware = applyMiddleware (
Original file line number Diff line number Diff line change @@ -2,14 +2,16 @@ var actions = require('./actions'),
22constants = require ( './constants' ) ;
33
44const middleware = ( twilioDevice , token , opts ) => store => {
5- token ( ) . then ( value => {
5+ const getToken = ( ) => token ( store . getState ( ) )
6+
7+ getToken ( ) . then ( value => {
68 twilioDevice . ready ( device => {
79 store . dispatch ( actions . changeDeviceStatus ( device ) ) ;
810 } ) ;
911
1012 twilioDevice . offline ( device => {
1113 store . dispatch ( actions . changeDeviceStatus ( device ) ) ;
12- token ( ) . then ( value => {
14+ getToken ( ) . then ( value => {
1315 twilioDevice . setup ( value , opts ) ;
1416 } )
1517 } ) ;
You can’t perform that action at this time.
0 commit comments