Frontend implementation of the real-time client

In our implementation, we will create a RealTimeClient class to wrap a SockJS object to provide channel-based communication. We will bind the instance of this client to Vue.prototype.$rt so that all of the Vue components can access the real-time client via the instance's $rt property. The following is an overview of the RealTimeClient class.

Let's have a look at the frontend/src/real-time-client.js file:

import Vue from 'vue'import SockJS from 'sockjs-client'class RealTimeClient {   constructor () {    ...  }  init (serverUrl, token) {    ...  }  logout () {    ...  }  connect () {    ...  }  subscribe (channel, handler) {    ...  }  unsubscribe (channel, handler) {    ...  }}export default new RealTimeClient()

As you can ...

Get Building Applications with Spring 5 and Vue.js 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.