summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@gnome.org>2008-12-14 18:00:20 +0100
committerBenjamin Otte <otte@gnome.org>2008-12-16 21:38:18 +0100
commit0dab90b5351f5bba533671537426f582149abc89 (patch)
treea23c952c02d0b4932f5242a65ccb5dae14114891
parent2cdc5065158df907df68fa30e413769309c80dbd (diff)
set NetConnection.isConnected and NetConnection.uri after connecting
-rw-r--r--swfdec/swfdec_as_strings.c2
-rw-r--r--swfdec/swfdec_rtmp_connection.c33
-rw-r--r--swfdec/swfdec_rtmp_connection.h4
-rw-r--r--swfdec/swfdec_rtmp_socket_rtmp.c6
4 files changed, 43 insertions, 2 deletions
diff --git a/swfdec/swfdec_as_strings.c b/swfdec/swfdec_as_strings.c
index 23859811..a03ce400 100644
--- a/swfdec/swfdec_as_strings.c
+++ b/swfdec/swfdec_as_strings.c
@@ -547,6 +547,8 @@ const SwfdecAsConstantStringValue swfdec_as_strings[] = {
SWFDEC_AS_CONSTANT_STRING ("onResult")
SWFDEC_AS_CONSTANT_STRING ("pageUrl")
SWFDEC_AS_CONSTANT_STRING ("videoFunction")
+ SWFDEC_AS_CONSTANT_STRING ("isConnected")
+ SWFDEC_AS_CONSTANT_STRING ("uri")
/* add more here */
{ 0, 0, "" }
};
diff --git a/swfdec/swfdec_rtmp_connection.c b/swfdec/swfdec_rtmp_connection.c
index e2842086..69034abb 100644
--- a/swfdec/swfdec_rtmp_connection.c
+++ b/swfdec/swfdec_rtmp_connection.c
@@ -25,6 +25,7 @@
#include <string.h>
+#include "swfdec_as_internal.h"
#include "swfdec_as_strings.h"
#include "swfdec_bots.h"
#include "swfdec_debug.h"
@@ -399,6 +400,7 @@ swfdec_rtmp_connection_close (SwfdecRtmpConnection *conn)
conn->socket = NULL;
swfdec_url_free (conn->url);
conn->url = NULL;
+ swfdec_rtmp_connection_set_connected (conn, NULL);
}
void
@@ -487,6 +489,11 @@ swfdec_rtmp_connection_send (SwfdecRtmpConnection *conn, SwfdecRtmpPacket *packe
* but that requires a g_queue_find_custom () and that's slow */
g_assert (packet->header.size == packet->buffer->length);
+ if (!swfdec_rtmp_connection_is_connected (conn)) {
+ SWFDEC_DEBUG ("ignoring send on closed connection");
+ return;
+ }
+
packet->buffer->length = 0;
send = g_queue_is_empty (conn->packets);
g_queue_push_head (conn->packets, packet);
@@ -495,3 +502,29 @@ swfdec_rtmp_connection_send (SwfdecRtmpConnection *conn, SwfdecRtmpPacket *packe
if (send)
swfdec_rtmp_socket_send (conn->socket);
}
+
+void
+swfdec_rtmp_connection_set_connected (SwfdecRtmpConnection *conn,
+ const char *url)
+{
+ SwfdecAsObject *object;
+ SwfdecAsValue *val, tmp;
+
+ g_return_if_fail (SWFDEC_IS_RTMP_CONNECTION (conn));
+
+ object = swfdec_as_relay_get_as_object (SWFDEC_AS_RELAY (conn));
+ val = swfdec_as_object_peek_variable (object, SWFDEC_AS_STR_isConnected);
+ if (val) {
+ SWFDEC_AS_VALUE_SET_BOOLEAN (val, url != NULL);
+ } else {
+ SWFDEC_FIXME ("something weird happens when isConnected was deleted");
+ }
+ /* FIXME: should not fail if variable exists but is constant */
+ if (url) {
+ SWFDEC_AS_VALUE_SET_STRING (&tmp, url);
+ } else {
+ SWFDEC_AS_VALUE_SET_UNDEFINED (&tmp);
+ }
+ swfdec_as_object_set_variable (object, SWFDEC_AS_STR_uri, &tmp);
+}
+
diff --git a/swfdec/swfdec_rtmp_connection.h b/swfdec/swfdec_rtmp_connection.h
index 38d916d1..4f285fa0 100644
--- a/swfdec/swfdec_rtmp_connection.h
+++ b/swfdec/swfdec_rtmp_connection.h
@@ -76,7 +76,7 @@ struct _SwfdecRtmpConnectionClass {
GType swfdec_rtmp_connection_get_type (void);
-#define swfdec_rtmp_connection_is_connected(conn) ((conn)->socket != NULL)
+#define swfdec_rtmp_connection_is_connected(conn) ((conn)->socket != NULL && (conn)->error == NULL)
void swfdec_rtmp_connection_connect (SwfdecRtmpConnection * conn,
const SwfdecURL * url);
void swfdec_rtmp_connection_close (SwfdecRtmpConnection * conn);
@@ -89,6 +89,8 @@ void swfdec_rtmp_connection_queue_control_packet
(SwfdecRtmpConnection * conn,
SwfdecRtmpPacket * packet);
+void swfdec_rtmp_connection_set_connected (SwfdecRtmpConnection * conn,
+ const char * url);
void swfdec_rtmp_connection_error (SwfdecRtmpConnection * conn,
const char * error,
...) G_GNUC_PRINTF (2, 3);
diff --git a/swfdec/swfdec_rtmp_socket_rtmp.c b/swfdec/swfdec_rtmp_socket_rtmp.c
index 2fdedb3a..7366ff74 100644
--- a/swfdec/swfdec_rtmp_socket_rtmp.c
+++ b/swfdec/swfdec_rtmp_socket_rtmp.c
@@ -63,8 +63,12 @@ static void
swfdec_rtmp_socket_rtmp_stream_target_open (SwfdecStreamTarget *target, SwfdecStream *stream)
{
SwfdecRtmpSocketRtmp *rtmp = SWFDEC_RTMP_SOCKET_RTMP (target);
+ SwfdecRtmpSocket *sock = SWFDEC_RTMP_SOCKET (target);
- rtmp->next = swfdec_rtmp_socket_next_buffer (SWFDEC_RTMP_SOCKET (target));
+ swfdec_rtmp_connection_set_connected (sock->conn,
+ swfdec_as_context_get_string (swfdec_gc_object_get_context (sock->conn),
+ swfdec_url_get_url (sock->conn->url)));
+ rtmp->next = swfdec_rtmp_socket_next_buffer (sock);
swfdec_rtmp_socket_rtmp_do_send (rtmp);
}