Skip to content

Instantly share code, notes, and snippets.

@chadnickbok
Created November 17, 2015 08:40
Show Gist options
  • Save chadnickbok/2bab102d28ae2576d270 to your computer and use it in GitHub Desktop.
Save chadnickbok/2bab102d28ae2576d270 to your computer and use it in GitHub Desktop.
rtcdc changes
diff --git a/python/example.py b/python/example.py
index 738c6c6..6d002fe 100755
--- a/python/example.py
+++ b/python/example.py
@@ -3,6 +3,9 @@
import pyrtcdc
import base64
+def on_connect(peer):
+ print "Connect!"
+
def on_channel(peer, channel):
print 'new channel %s created' %(channel.label)
channel.on_message = on_message
@@ -14,7 +17,7 @@ def on_message(channel, datatype, data):
print 'received data from channel %s: %s' %(channel.label, data)
channel.send(pyrtcdc.DATATYPE_STRING, 'hi')
-peer = pyrtcdc.PeerConnection(on_channel, on_candidate, stun_server='stun.services.mozilla.com')
+peer = pyrtcdc.PeerConnection(on_channel, on_candidate, on_connect, stun_server='stun.services.mozilla.com')
offer = peer.generate_offer()
print 'base64 encoded local offer sdp:\n%s\n' %(base64.b64encode(offer))
@@ -41,4 +44,5 @@ while True:
print 'invalid remote candidate sdp'
print 'enter remote candidate sdp:'
+print("Waiting...")
peer.loop()
diff --git a/src/rtcdc.c b/src/rtcdc.c
index a0405fd..f5c952a 100644
--- a/src/rtcdc.c
+++ b/src/rtcdc.c
@@ -26,6 +26,10 @@ create_rtcdc_transport(struct rtcdc_peer_connection *peer, int role)
if (peer == NULL)
return -1;
+ if (role == RTCDC_PEER_ROLE_CLIENT) {
+ fprintf(stderr, "Creating client peer transport\n");
+ }
+
struct rtcdc_transport *transport =
(struct rtcdc_transport *)calloc(1, sizeof *transport);
if (transport == NULL)
@@ -206,9 +210,9 @@ rtcdc_parse_offer_sdp(struct rtcdc_peer_connection *peer, const char *offer)
int pos = 0;
int remote_port = 0;
for (int i = 0; lines && lines[i]; ++i) {
- if (g_str_has_prefix(lines[i], "a=sctp-port:")) {
- char **columns = g_strsplit(lines[i], ":", 0);
- remote_port = atoi(columns[1]);
+ if (g_str_has_prefix(lines[i], "m=application")) {
+ char **columns = g_strsplit(lines[i], " ", 0);
+ remote_port = atoi(columns[3]);
if (remote_port <= 0)
return -1;
peer->transport->sctp->remote_port = remote_port;
@@ -217,8 +221,10 @@ rtcdc_parse_offer_sdp(struct rtcdc_peer_connection *peer, const char *offer)
char **columns = g_strsplit(lines[i], ":", 0);
if (strcmp(columns[1], "active") == 0 && peer->role == RTCDC_PEER_ROLE_CLIENT) {
peer->role = RTCDC_PEER_ROLE_SERVER;
+ fprintf(stderr, "SWITCHING ROLE TO SERVER\n");
} else if (strcmp(columns[1], "passive") == 0 && peer->role == RTCDC_PEER_ROLE_SERVER) {
- peer->role = RTCDC_PEER_ROLE_CLIENT;
+ // peer->role = RTCDC_PEER_ROLE_CLIENT;
+ fprintf(stderr, "SWITCHING ROLE TO CLIENT\n");
} else { // actpass
// nothing to do
}
@@ -359,6 +365,12 @@ startup_thread(gpointer user_data)
struct dtls_transport *dtls = transport->dtls;
struct sctp_transport *sctp = transport->sctp;
+ if (peer->role == RTCDC_PEER_ROLE_CLIENT) {
+ fprintf(stderr, "CLIENT ROLE\n");
+ } else {
+ fprintf(stderr, "WEIRD ROLE\n");
+ }
+
while (!peer->exit_thread && !ice->negotiation_done)
g_usleep(2500);
if (peer->exit_thread)
@@ -393,9 +405,11 @@ startup_thread(gpointer user_data)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
sconn.sconn_len = sizeof *sctp;
#endif
- if (usrsctp_connect(sctp->sock, (struct sockaddr *)&sconn, sizeof sconn) < 0) {
+ fprintf(stderr, "usrsctp_connect\n");
+ int res = usrsctp_connect(sctp->sock, (struct sockaddr *)&sconn, sizeof sconn);
+ if (res < 0) {
#ifdef DEBUG_SCTP
- fprintf(stderr, "SCTP connection failed\n");
+ fprintf(stderr, "SCTP connection failed: %d\n", res);
#endif
} else {
#ifdef DEBUG_SCTP
@@ -416,8 +430,10 @@ startup_thread(gpointer user_data)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
sconn.sconn_len = sizeof *sctp;
#endif
+ fprintf(stderr, "usrsctp_listen\n");
usrsctp_listen(sctp->sock, 1);
socklen_t len = sizeof sconn;
+ fprintf(stderr, "usrsctp accept\n");
struct socket *s = usrsctp_accept(sctp->sock, (struct sockaddr *)&sconn, &len);
if (s) {
#ifdef DEBUG_SCTP
diff --git a/src/sdp.c b/src/sdp.c
index ec7c836..14c4158 100644
--- a/src/sdp.c
+++ b/src/sdp.c
@@ -38,7 +38,7 @@ generate_local_sdp(struct rtcdc_transport *transport, int client)
"s=-\r\n"
"t=0 0\r\n"
"a=msid-semantic: WMS\r\n");
- pos += sprintf(buf + pos, "m=application 1 UDP/DTLS/SCTP webrtc-datachannel\r\n");
+ pos += sprintf(buf + pos, "m=application 9 DTLS/SCTP 5000\r\n");
pos += sprintf(buf + pos, "c=IN IP4 0.0.0.0\r\n");
gchar *lsdp = nice_agent_generate_local_sdp(ice->agent);
@@ -53,14 +53,16 @@ generate_local_sdp(struct rtcdc_transport *transport, int client)
g_strfreev(lines);
pos += sprintf(buf + pos, "a=fingerprint:sha-256 %s\r\n", ctx->fingerprint);
-
- if (client)
- pos += sprintf(buf + pos, "a=setup:active\r\n");
- else
+ /*if (client) {
+ pos += sprintf(buf + pos, "a=setup:actpass\r\n");
+ } else {
pos += sprintf(buf + pos, "a=setup:passive\r\n");
+ }*/
+ pos += sprintf(buf + pos, "a=setup:active\r\n");
+
pos += sprintf(buf + pos, "a=mid:data\r\n");
- pos += sprintf(buf + pos, "a=sctp-port:%d\r\n", sctp->local_port);
+ pos += sprintf(buf + pos, "a=sctpmap:%d webrtc-datachannel 1024\r\n", sctp->local_port);
return strndup(buf, pos);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment