Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if session is not live #8

Open
omidb opened this issue Feb 22, 2018 · 2 comments
Open

Check if session is not live #8

omidb opened this issue Feb 22, 2018 · 2 comments

Comments

@omidb
Copy link

omidb commented Feb 22, 2018

Let's say we have a session id, how can I check if that session is alive or already has been closed?

@jroper
Copy link
Member

jroper commented Apr 19, 2018

Play socket.io offers a stream centric view of socket.io - if the stream is running, the session is alive, if it's not, it's been closed. If you want to maintain that state somewhere, you could use watchTermination on the stream to update a map somewhere of active stream ids, but note that that won't work in a multi node environment, Play socket.io is designed fundamentally to support multi node environments. You could maintain the map in a cluster singleton actor.

@omidb
Copy link
Author

omidb commented Apr 19, 2018

Currently what I am doing is very similar to what you mentioned, I use onStop and onStart to keep track of them:

class SocketIOEngine(socketIO: SocketIO , system: ActorSystem, subscriberActor: ActorRef @@ SubscriberActor,
                     myLagomService: MyLagomService)(implicit mat: Materializer) {


  val decoder = decodeByName {
    ....
  }

  val encoder = encodeByType {
    ....
  }

  def flow(id:String) = {
    implicit val timeout = Timeout(1.second)
    ActorFlow.actorRef { out =>
      DashboardActor.props(id, out, subscriberActor, lagomService)
    }(system, mat)
  }

  val controller: EngineIOController = socketIO.builder
    .addNamespace(decoder, encoder){
      case (SocketIOSession(sessionId, out),"/chat") => {
        flow(sessionId)
      }
    }
    .createController()
}

I don't know how well it scales, becasue there is only one actor that keeps track of everything. On the other hand, I am subscribing to bunch of events coming from Lagom Kafka topics in the same actor and send them to the front end actors.
Also, (not related to the Play Socket but more generally related to Lagom and Play connections) it gets ugly to do encoding and decoding of all these messages and convert them around. Is there any way to wire these nicer? I was thinking, if we could have the sockets in Play like what we have in Lagom services (two Sources), maybe then we can wire them around without all these conversion layers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants