From e954543d5b6a231155ee8f55c9d0c53c3a43a11d Mon Sep 17 00:00:00 2001 From: zztkm Date: Wed, 18 Dec 2024 18:49:18 +0900 Subject: [PATCH] =?UTF-8?q?data=5Fchannels=20header=20=E7=A2=BA=E8=AA=8D?= =?UTF-8?q?=E7=94=A8=E3=82=B3=E3=83=BC=E3=83=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shiguredo/sora/quickstart/MainActivity.kt | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/quickstart/src/main/kotlin/jp/shiguredo/sora/quickstart/MainActivity.kt b/quickstart/src/main/kotlin/jp/shiguredo/sora/quickstart/MainActivity.kt index ef03b69..d579ecd 100644 --- a/quickstart/src/main/kotlin/jp/shiguredo/sora/quickstart/MainActivity.kt +++ b/quickstart/src/main/kotlin/jp/shiguredo/sora/quickstart/MainActivity.kt @@ -15,6 +15,7 @@ import jp.shiguredo.sora.quickstart.databinding.ActivityMainBinding import jp.shiguredo.sora.sdk.camera.CameraCapturerFactory import jp.shiguredo.sora.sdk.channel.SoraMediaChannel import jp.shiguredo.sora.sdk.channel.option.SoraMediaOption +import jp.shiguredo.sora.sdk.channel.signaling.message.OfferMessage import jp.shiguredo.sora.sdk.channel.signaling.message.PushMessage import jp.shiguredo.sora.sdk.error.SoraErrorReason import jp.shiguredo.sora.sdk.util.SoraLogger @@ -26,6 +27,7 @@ import permissions.dispatcher.OnPermissionDenied import permissions.dispatcher.OnShowRationale import permissions.dispatcher.PermissionRequest import permissions.dispatcher.RuntimePermissions +import java.nio.ByteBuffer @RuntimePermissions class MainActivity : AppCompatActivity() { @@ -142,6 +144,19 @@ class MainActivity : AppCompatActivity() { } } } + + override fun onOfferMessage(mediaChannel: SoraMediaChannel, offer: OfferMessage) { + Log.d("kensaku", "onOfferMessage: offer=$offer") + } + + override fun onDataChannelMessage( + mediaChannel: SoraMediaChannel, + label: String, + data: ByteBuffer + ) { + val message = mediaChannel.dataToString(data) + Log.d("kensaku", "onDataChannelMessage: label=$label, message=$message") + } } @NeedsPermission(value = [Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO]) @@ -161,11 +176,34 @@ class MainActivity : AppCompatActivity() { enableMultistream() } + val dataChannels = listOf( + mapOf( + "label" to "#spam", + "direction" to "sendrecv", + ), + mapOf( + "label" to "#egg", + "max_retransmits" to 10, + "ordered" to false, + "protocol" to "bob", + "compress" to false, + "direction" to "recvonly", + "header" to listOf( + mapOf( + "type" to "sender_connection_id" + ) + ) + ), + ) + mediaChannel = SoraMediaChannel( context = this, signalingEndpoint = BuildConfig.SIGNALING_ENDPOINT, channelId = BuildConfig.CHANNEL_ID, signalingMetadata = Gson().fromJson(BuildConfig.SIGNALING_METADATA, Map::class.java), + dataChannelSignaling = true, + ignoreDisconnectWebSocket = false, + dataChannels = dataChannels, mediaOption = option, listener = channelListener )