I am trying dispatch an action whenever a response appear on live socket using redux-saga. I have been able to reach to the line of code where action should be put(dispatched) but only in this live sockets case live actions are not dispatching.
Here is my code:
export function* watchEditorAcceptInvitatioRequest(action) {
yield takeEvery(START_EDITOR_ACCEPT_INVITATION_SOCKET, edditorAcceptInvitationSocket)
}
export function* edditorAcceptInvitationSocket(action) {
const {token, user_id} = action.payload
const subscription = SocketIo.subscribe(token, '/broadcasting/authTest')
yield put(listenEditorAcceptInvitationSocket())
let result = yield call(SocketIo.listen, subscription, `new-test-channel.${user_id}`,
'.new-test-test', (response) => edditorAcceptInvitationReceived({
func: receiveEditorAcceptInvitationSocket,
response: response
}))
}
export function* edditorAcceptInvitationReceived(action) {
while(true) {
console.log(action.response) // I am seeing this in response but the action put in blow line
yield put(action.func(action.response))
}
}
Below is socket subscription and listening code:
import Echo from 'laravel-echo'
import Socketio from 'socket.io-client'
const BASE_URL = 'https://www.my domain.com'
const PORT = 1111
const subscribe = (token, authEndpoint) => new Echo({
broadcaster: 'socket.io',
host: `${BASE_URL}:${PORT}`,
client: Socketio,
authEndpoint: authEndpoint,
auth: {
headers: {
Authorization: 'Bearer ' + token,
Accept: 'application/json',
},
},
})
const listen = (echo, channel, event, callback) => {
echo.private(channel).listen(event, e => {
const generator = callback(e)
generator.next()
})
}
export default {
subscribe,
listen
}
What is missing here, Any help will be appreciated.