Websockets and Polling - ARA-Trans/iAM GitHub Wiki
This app was initially built to use Websockets for live update communication from the Node app to the Vue app. This was implemented using socket.io. Websockets are the preferable alternative to polling for live updates, but the WS/WSS protocol is not supported on PennDOT's servers.
Reverting to using websockets:
If the app is being deployed to another client, on servers that support the WS/WSS protocol, the change can be easily reversed. The change from websockets to a custom polling solution was merged in pull request #582 ("Vnext/554 - Custom polling"). The PR can be referenced for a complete understanding of the custom polling, but below is a step-by-step guide for enabling websockets with socket.io.
Changes to the Node app:
In app.js:
-
Socket.io will need to be imported.
-
The import of the pollingRouter will no longer be necessary.
-
All calls to the emitEvent function should be replaced with io.emit in the *.watch() handlers. The parameters are identical.
-
The pollingRouter should be removed from the list of routers in the app.use() call near the bottom of the file.
Changes to the Vue app:
In App.vue:
-
Remove the call to generatePollingSessionIdAction
-
Remove the setInterval of pollEventsAction
In main.ts:
- Add the following code:
import VueSocketio from 'vue-socket.io-extended';
import io from 'socket.io-client';
const socketioClient = io(process.env.VUE_APP_NODE_URL, { path: process.env.VUE_APP_SOCKET_PATH, upgrade: true, transports: ['websocket'] });
Vue.use(VueSocketio, socketioClient, { store });