2017-08-17 06:28:41 +00:00
|
|
|
import { take, put, call } from 'redux-saga/effects';
|
2017-08-17 01:06:31 +00:00
|
|
|
import { METEOR } from '../actions/actionsTypes';
|
|
|
|
import RocketChat from '../lib/rocketchat';
|
|
|
|
|
|
|
|
import { connectSuccess, connectFailure } from '../actions/connect';
|
|
|
|
|
|
|
|
function connect(...args) {
|
|
|
|
return RocketChat.connect(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
const watchConnect = function* watchConnect() {
|
|
|
|
while (true) {
|
|
|
|
yield take(METEOR.REQUEST);
|
2017-08-17 01:09:44 +00:00
|
|
|
console.log('\n\n[METEOR CONNECTED]\n\n');
|
2017-08-17 01:06:31 +00:00
|
|
|
try {
|
|
|
|
const response = yield call(connect);
|
|
|
|
yield put(connectSuccess(response));
|
|
|
|
} catch (err) {
|
|
|
|
yield put(connectFailure(err.status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-08-17 06:28:41 +00:00
|
|
|
export default watchConnect;
|