Skip to content

Commit 5c62c62

Browse files
committed
Send offer from dialer to listener
1 parent 87935ae commit 5c62c62

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/main/kotlin/com/coder/gateway/sdk/Tunneler.kt

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.coder.gateway.sdk
22

33
import com.coder.gateway.models.BrokerMessage
4-
import com.coder.gateway.models.UriScheme
54
import com.coder.gateway.models.Workspace
65
import com.google.gson.Gson
76
import com.google.gson.GsonBuilder
@@ -30,6 +29,7 @@ import okhttp3.WebSocket
3029
import okhttp3.WebSocketListener
3130
import okhttp3.logging.HttpLoggingInterceptor
3231
import okio.ByteString
32+
import okio.ByteString.Companion.encodeUtf8
3333
import java.net.URL
3434
import java.time.Instant
3535
import java.util.logging.Logger
@@ -112,18 +112,19 @@ class Tunneler(val brokerAddr: URL, val token: String, val workspace: Workspace,
112112
logger.info("created peer connection")
113113

114114
logger.info("creating control channel { \"proto\" : \"control\"}")
115-
rtc.createDataChannel("control", RTCDataChannelInit().apply {
115+
rtc.createDataChannel("control", RTCDataChannelInit().apply {
116116
protocol = "control"
117117
ordered = true
118118
})
119-
rtc.createOffer(RTCOfferOptions(), object: CreateSessionDescriptionObserver {
119+
rtc.createOffer(RTCOfferOptions(), object : CreateSessionDescriptionObserver {
120120
override fun onSuccess(sessionDescription: RTCSessionDescription?) {
121121
logger.info("created offer {\"offer\": ${sessionDescription}}")
122122
rtc.setLocalDescription(sessionDescription, object : SetSessionDescriptionObserver {
123123
override fun onSuccess() {
124124
logger.info("set local offer $sessionDescription with success")
125125
val offerMsg = BrokerMessage(sessionDescription!!, options.iceServers, options.turnRemoteProxyURL.toString())
126126
logger.info("sending offer message {\"msg\": ${gson.toJson(offerMsg)}}")
127+
connection.send(gson.toJson(offerMsg).encodeUtf8())
127128
}
128129

129130
override fun onFailure(p0: String?) {
@@ -134,18 +135,20 @@ class Tunneler(val brokerAddr: URL, val token: String, val workspace: Workspace,
134135
}
135136

136137
override fun onFailure(p0: String?) {
138+
logger.warning("onFailure to set local $p0 with success")
137139
TODO("Not yet implemented")
138140
}
139141
})
140142

141-
return Dialer(connection,rtc.createDataChannel("data_channel_tmp", RTCDataChannelInit()), rtc)
143+
return Dialer(connection, rtc.createDataChannel("data_channel_tmp", RTCDataChannelInit()), rtc)
142144
}
145+
143146
private fun newPeerConnection(servers: List<RTCIceServer>, dialer: TURNProxyDialer, connection: WebSocket): RTCPeerConnection {
144147
val configuration = RTCConfiguration().apply {
145148
iceServers = servers
146149
if (servers.size == 1) {
147150
val url = iceServers[0].urls[0]
148-
if (url.startsWith( "turn") || url.startsWith("turns")) {
151+
if (url.startsWith("turn") || url.startsWith("turns")) {
149152
this.iceTransportPolicy = RTCIceTransportPolicy.RELAY
150153
}
151154
}
@@ -182,9 +185,7 @@ data class TURNProxyDialer(val baseURL: URL, val token: String)
182185
* inside a workspace. The opposing end of the WebSocket messages
183186
* should be proxied with a Listener.
184187
*/
185-
class Dialer(val connection: WebSocket, val ctrl: RTCDataChannel, val rtc: RTCPeerConnection) {
186-
187-
}
188+
class Dialer(val connection: WebSocket, val ctrl: RTCDataChannel, val rtc: RTCPeerConnection)
188189

189190
data class ICECandidateInit(
190191
@SerializedName("candidate") val candidate: String,

0 commit comments

Comments
 (0)