mirror of
				https://github.com/livebook-dev/livebook.git
				synced 2025-10-31 15:56:05 +08:00 
			
		
		
		
	Handle direct event messages in JS view channel (#1332)
This commit is contained in:
		
							parent
							
								
									e8920257cd
								
							
						
					
					
						commit
						c68df08849
					
				
					 2 changed files with 19 additions and 0 deletions
				
			
		|  | @ -82,6 +82,15 @@ defmodule LivebookWeb.JSViewChannel do | |||
|     {:noreply, socket} | ||||
|   end | ||||
| 
 | ||||
|   def handle_info({:event, event, payload, %{ref: ref}}, socket) do | ||||
|     with {:error, error} <- try_push(socket, "event:#{ref}", [event], payload) do | ||||
|       message = "Failed to serialize widget data, " <> error | ||||
|       push(socket, "error:#{ref}", %{"message" => message}) | ||||
|     end | ||||
| 
 | ||||
|     {:noreply, socket} | ||||
|   end | ||||
| 
 | ||||
|   def handle_info({:pong, _, %{ref: ref}}, socket) do | ||||
|     push(socket, "pong:#{ref}", %{}) | ||||
|     {:noreply, socket} | ||||
|  |  | |||
|  | @ -47,6 +47,16 @@ defmodule LivebookWeb.JSViewChannelTest do | |||
|     assert_receive {:event, "ping", [1, 2, 3], %{origin: _origin}} | ||||
|   end | ||||
| 
 | ||||
|   test "sends server events to the target client", %{socket: socket} do | ||||
|     push(socket, "connect", %{"session_token" => session_token(), "ref" => "1", "id" => "id1"}) | ||||
| 
 | ||||
|     assert_receive {:connect, from, %{}} | ||||
|     send(from, {:connect_reply, [1, 2, 3], %{ref: "1"}}) | ||||
| 
 | ||||
|     send(from, {:event, "ping", [1, 2, 3], %{ref: "1"}}) | ||||
|     assert_push "event:1", %{"root" => [["ping"], [1, 2, 3]]} | ||||
|   end | ||||
| 
 | ||||
|   describe "binary payload" do | ||||
|     test "initial data", %{socket: socket} do | ||||
|       push(socket, "connect", %{"session_token" => session_token(), "ref" => "1", "id" => "id1"}) | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue