Skip to content

Commit

Permalink
data_channels header 確認用コード
Browse files Browse the repository at this point in the history
  • Loading branch information
zztkm committed Dec 18, 2024
1 parent 8fc0923 commit e954543
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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])
Expand All @@ -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
)
Expand Down

0 comments on commit e954543

Please sign in to comment.