-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added LEAP to drop down UrbanOS-Public/smartcitiesdata#487 co-authored-by: Scott Millard <smillard@hntb.com> * handling leap position updates in reducer UrbanOS-Public/smartcitiesdata#487 co-authored-by: Scott Millard <smillard@hntb.com> * using correct icon for LEAP; duplicated websocket saga for LEAP UrbanOS-Public/smartcitiesdata#487 co-authored-by: mcsearchin <abrock17@gmail.com> * DRYd up gee 2 web socket sagas UrbanOS-Public/smartcitiesdata#487 co-authored-by: Scott Millard <smillard@hntb.com> Co-authored-by: smillardHNTB <37001890+smillardHNTB@users.noreply.github.com>
- Loading branch information
1 parent
42e2610
commit 9d9ea34
Showing
14 changed files
with
202 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import webSocketSaga from './websocket' | ||
import cotaWebSocketSaga from './cotaWebSocket' | ||
import leapWebSocketSaga from './leapWebSocket' | ||
import routeSaga from './route' | ||
import { fork, all } from 'redux-saga/effects' | ||
|
||
export default function* allSagas() { | ||
yield all([ | ||
fork(webSocketSaga), | ||
fork(cotaWebSocketSaga), | ||
fork(leapWebSocketSaga), | ||
fork(routeSaga) | ||
]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { call, take, put, race, select } from 'redux-saga/effects' | ||
import * as socketUtils from './websocket-utils' | ||
import { leapPositionUpdate, ROUTE_FILTER } from '../actions' | ||
import { LEAP } from '../variables' | ||
|
||
const createChannel = (socket) => { | ||
return socket.channel('streaming:easymile__linden_positions', {}) | ||
} | ||
|
||
const fromServer = function* (eventChannel) { | ||
while (true) { | ||
const message = yield take(eventChannel) | ||
if (message !== undefined) { | ||
message.provider = LEAP | ||
} | ||
|
||
let provider = yield select(state => state.provider.name) | ||
if (provider === LEAP) { | ||
yield put(leapPositionUpdate(message)) | ||
} | ||
} | ||
} | ||
|
||
const fromEventBus = function* (channel) { | ||
while (true) { | ||
const action = yield take(ROUTE_FILTER) | ||
if (LEAP === action.filter[0]) { | ||
channel.push('filter', {}) | ||
} | ||
} | ||
} | ||
|
||
const doSaga = function* () { | ||
const socket = yield call(socketUtils.createSocket, `${window.WEBSOCKET_HOST}/socket`) | ||
const channel = yield call(createChannel, socket) | ||
const eventChannel = yield call(socketUtils.createEventChannel, channel) | ||
|
||
yield race([call(fromEventBus, channel), call(fromServer, eventChannel)]) | ||
} | ||
|
||
export default function* leapWebSocketSaga() { | ||
while (true) { | ||
const action = yield take(ROUTE_FILTER) | ||
yield call(doSaga, action) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { eventChannel } from 'redux-saga' | ||
import { Socket } from 'phoenix' | ||
|
||
export const createSocket = (socketUrl) => { | ||
let socket = new Socket(socketUrl) | ||
socket.connect() | ||
return socket | ||
} | ||
|
||
export const createChannel = (socket, channelName, filter) => { | ||
const channel = socket.channel(channelName, filter) | ||
socket.onOpen(() => channel.push('filter', filter)) | ||
|
||
return channel | ||
} | ||
|
||
export const createEventChannel = channel => { | ||
return eventChannel(emit => { | ||
channel.on('update', emit) | ||
|
||
channel.join() | ||
.receive('ok', () => console.log('Connection Successful')) | ||
.receive('error', ({ reason }) => console.log('failed join', reason)) | ||
.receive('timeout', () => console.log('Networking issue. Still waiting...')) | ||
|
||
return unsubscribe | ||
}) | ||
} | ||
|
||
const unsubscribe = () => { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const COTA = 'COTA' | ||
export const COTA = 'COTA' | ||
export const LEAP = 'LEAP' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const mockString = '<svg>easymile</svg>' | ||
export default mockString |