PieSocket Realtime SDK for Android written in Java.
Let's start by adding PieSocket Android SDK as a dependency to your application.
implementation("com.piesocket:channels-sdk:7.0.0")
implementation 'com.piesocket:channels-sdk:7.0.0'
<dependency>
<groupId>com.piesocket</groupId>
<artifactId>channels-sdk</artifactId>
<version>7.0.0</version>
</dependency>
Setup manifest permissions as instructed here.
Use following code to create a Channel with PieSocket's managed WebSocket servers.
Get your API key and Cluster ID here: Get API Key
PieSocketOptions options = new PieSocketOptions();
options.setClusterId("demo");
options.setApiKey("VCXCEuvhGcBDP7XhiJJUDvR1e1D3eiVjgZ9VRiaV");
PieSocket piesocket = new PieSocket(options);
Channel channel = piesocket.join("chat-room-1");Use following code to create a Channel with PieSocket self-hosted realtime servers.
PieSocketOptions options = new PieSocketOptions();
options.setClusterDomain("localhost:4001");
options.setSsl(false);
PieSocket piesocket = new PieSocket(options);
Channel channel = piesocket.join("chat-room-1");PieSocket Channels is a scalable WebSocket API service with following features:
- Authentication
- Private Channels
- Presence Channels
- Publish messages with REST API
- Auto-scalability
- Webhooks
- Analytics
- Authentication
- Upto 60% cost savings
Set options.setVersion("4") to share a single WebSocket across every
join() call. join() still returns a Channel synchronously — the
multiplexing happens in the background.
PieSocketOptions options = new PieSocketOptions();
options.setClusterId("demo");
options.setApiKey("VCXCEuvhGcBDP7XhiJJUDvR1e1D3eiVjgZ9VRiaV");
options.setVersion("4");
PieSocket piesocket = new PieSocket(options);
Channel chat = piesocket.join("chat-room"); // opens the socket
Channel alerts = piesocket.join("alerts"); // rides the same socket
chat.listen("message", event -> { /* ... */ });
alerts.publishEvent("ping", new JSONObject().put("at", System.currentTimeMillis()), null);join()stays synchronous. Listen forsystem:connectedon the primary channel (the firstjoin()); secondary channels' subscribe acks are handled internally, not delivered to their own listeners.- Delta presence. Full roster once as
system::member_list, then kept in sync fromsystem::member_joined/system::member_left. Callchannel.refreshMembers()(returns aCompletableFuture<JSONArray>). - All v4 system events are double-colon (
system::member_joined, …). publishEvent(event, data, meta)sends a structured payload directly.- Binary. Inbound binary arrives as a
system::binaryevent whosedatais a base64 string.channel.sendBinary(byte[])sends a raw binary frame (primary channel only) — the server re-wraps it assystem::binaryfor every other client, JS/Flutter peers included.
Programmable WebRTC over v4, built on the bundled
io.github.webrtc-sdk:android. Signalling rides its own rtc:: namespace —
a plain relay, so Android, Flutter and JS/web clients interoperate in one
room.
PieRTCOptions rtc = new PieRTCOptions(getApplicationContext());
rtc.video = true;
rtc.audio = true;
rtc.onLocalVideo = (stream, pieRTC) -> { /* stream.videoTracks.get(0).addSink(renderer) */ };
rtc.onParticipantJoined = (uuid, stream) -> { /* attach remote stream */ };
rtc.onParticipantLeft = uuid -> { /* remove renderer */ };
Channel room = piesocket.join("video-room", rtc);PieRTCOptions.contextis required.pieRTC.getEglBaseContext()feedsSurfaceViewRenderer.init(...).pieRTC.shareScreen()— one call. The SDK runs theMediaProjectionpermission prompt and the foreground service itself (both declared in the SDK manifest, merged automatically);pieRTC.stopScreenShare()stops.pieRTC.dispose()/piesocket.leave(room)releases native resources.
Manifest permissions for PieRTC:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />system:connected is the event fired when WebSocket connection is ready, get a full list system messages here: PieSocket System Messages
For usage examples and more information, refer to: Official SDK docs