setupWebSocket()

in frontend/src/WebSocketClient.js [18:49]


    setupWebSocket(channelArn){
        if (this.channelArn === channelArn) {
            return;
        }
        this.channelArn = channelArn;
        const webSocketUrl = WEBSOCKET_API_ENDPOINT + `?channelarn=` + channelArn;

        this.ws = new WebSocket(webSocketUrl);

        this.ws.onmessage = msg => {
            const [, dispatch] = this.context;
            const message = JSON.parse(msg.data)
            switch(message.type) {
                case 'INITIAL_STATE':
                    console.debug('INIT STATE', message.questions)
                    dispatch({
                        type: SERVER_SET_QUESTIONS_ACTION,
                        questions: message.questions,
                    })
                    break;
                case 'UPDATES':
                    console.debug('UPDATE', message.updates)
                    dispatch({
                        type: SERVER_UPDATE_QUESTIONS_ACTION,
                        updates: message.updates,
                    })
                    break;
                default:
                    return;
            }
        }
    }