hapijs / nes

WebSocket adapter plugin for hapi routes
Other
502 stars 87 forks source link

Intermittent Publish #253

Closed ryanramage closed 6 years ago

ryanramage commented 6 years ago

I am trying to use nes, and it nice because it was so easy to set up.

Issue is some publish payloads dont get to the subscriber. Usually for sure the first one or two get delivered, but some subsequents ones dont, and then later on they will. No idea why.

code snips (both client and serve are at nes@9.0.1)

Server

server.subscription('/app/marshall/{spaceId}')
server.publish(`/app/marshall/${spaceId}`, {body, conversationId})

Client

import constants from '@/constants.js'
import { logError } from '@/helpers/api-error-handling.js'

const header = require('basic-auth-header')
const NesClient = require('nes').Client

export default function createWsClient (store) {
  const client = new NesClient(constants.apis.grandcentral.wsUrl)
  const idToken = store.state.auth.auth.idToken
  const { spaceId } = store.state.config

  function handler (update) {
    /* eslint-disable */console.log(update, store)/* eslint-enable */
  }

  async function start () {
    try {
      await client.connect({
        auth: {
          headers: {
            authorization: header(spaceId, idToken)
          }
        }
      })
      client.subscribe(`/app/marshall/${spaceId}`, handler)
    } catch (err) {
      logError(err)
    }
  }
  start()
}
hueniverse commented 6 years ago

So many things can cause websocket issues.

Regardless you should await client.subscribe().

ryanramage commented 6 years ago

thanks. good catch.

ryanramage commented 6 years ago

ok, changes made, and still getting the same behaviour.

I understand that websockets can be flaky. We are in a pretty stable local dev environment, so we are ruling out mobile connectivity/reconnect issues.

Only other thing I can think of is we have an older hapi version (13.5.3). Maybe there is some interplay with that causing issues. I will try and upgrade.

hueniverse commented 6 years ago

Which version of nes are you using? Did you check all the bug fixes since then?

ryanramage commented 6 years ago

both client and serve are at nes@9.0.1.

I'm sorry, i am jumping ship to use the ws module direct. I will leave my branch of my app available if you want me to test anything.

ryanramage commented 6 years ago

And I appreciate you being responsive to my issue. If there is anything else to provide you with, let me know.

hueniverse commented 6 years ago

nes 9 doesn't work with hapi 13. It requires hapi 17. Not sure what you are doing there. Closing since you are no longer using it.

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.