Hacker News new | past | comments | ask | show | jobs | submit login

Livebook, which is an elixir code notebook built with LiveView includes collaborative editing with presence, so it absolutely can be used in that domain. LiveView is built on phoenix channels, so it's all bidirectional communication. The client can send events from JavaScript. We use js hooks for the pings in LiveBeats for example:

    //js
    Hooks.Ping = {
      mounted(){
        this.handleEvent("pong", () => {
          let rtt = Date.now() - this.nowMs
          this.el.innerText = `ping: ${rtt}ms`
          this.timer = setTimeout(() => this.ping(rtt), 1000)
        })
        this.ping(null)
      },
      destroyed(){ clearTimeout(this.timer) },
      ping(rtt){
        this.nowMs = Date.now()
        this.pushEvent("ping", {rtt: rtt})
      }
    }

    //liveview
    defp handle_event("ping", %{"rtt" => rtt}, socket) do
      {:halt,
       socket
       |> rate_limited_ping_broadcast(socket.assigns.current_user, rtt)
       |> push_event("pong", %{})}
    end



Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: