-
Notifications
You must be signed in to change notification settings - Fork 98
Open
Description
My channel.ex file:
def handle_in("locations", _payload, socket) do
broadcast!(socket, "locations", %{ping: "succeed"})
{:reply, {:ok, %{ping: "succeed"}}, socket}
endMy MainActivity.ex
package com.example.phoenix_channel_test;
import androidx.appcompat.app.AppCompatActivity;
import org.phoenixframework.channels.*;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
Socket socket;
Channel channel;
private Button start;
private TextView output;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
start = (Button) findViewById(R.id.start);
output = (TextView) findViewById(R.id.output);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri.Builder url = Uri.parse( "ws://192.168.1.4:4000/socket/websocket" ).buildUpon();
try {
socket = new Socket(url.build().toString());
socket.connect();
channel = socket.chan("user_location:lobby", null);
channel.join();
ObjectNode node = new ObjectNode(JsonNodeFactory.instance);
channel.push("locations", node); // this line is not working
channel.on("locations", new IMessageCallback() {
@Override
public void onMessage(Envelope envelope) {
System.out.println("NEW MESSAGE: " + envelope.toString());
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}In MainActivity.java this line channel.push("locations", node); should respond to the function in channel.ex
def handle_in("locations", _payload, socket) do
broadcast!(socket, "locations", %{ping: "succeed"})
{:reply, {:ok, %{ping: "succeed"}}, socket}
end
But it is not working, Can anyone please help me out !
Metadata
Metadata
Assignees
Labels
No labels