Skip to content

Commit

Permalink
add re-cycle button for refreshing videos
Browse files Browse the repository at this point in the history
  • Loading branch information
lucabaldesi committed Nov 30, 2018
1 parent 31b47e2 commit 0ff046b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
15 changes: 14 additions & 1 deletion Public/assets/partyhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,15 @@ function Streamer(id, ipaddr, port) {
var head = document.createElement("div");
head.classList.add("panel-heading");
head.classList.add("text-center");
head.innerHTML = id2nickname(ch.name);
head.innerHTML = id2nickname(ch.name) + " - ";

var reload_btn = document.createElement("span");
reload_btn.innerHTML = "♻";
reload_btn.title = "Recycle";
reload_btn.style.cursor = "crosshair";
reload_btn.setAttribute('href', '#');
reload_btn.onclick = function() { reload_stream(ch.name); };
head.appendChild(reload_btn);

div.appendChild(head);
div.appendChild(vid);
Expand Down Expand Up @@ -457,6 +465,11 @@ function update_channels(chs)
channels = chs;
}

function reload_stream(name)
{
remote_objs.del_streamer(name);
}

function fetch_channels()
{
Janus.log("Fetching channels");
Expand Down
28 changes: 14 additions & 14 deletions src/janus_instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@

#define INVALID_PID -1

#define JANUS_MSG_SESSION_CREATE "{\"transaction\": \"random\", \"janus\": \"create\"}"
#define JANUS_MSG_SESSION_KEEPALIVE "{\"transaction\": \"ciao\", \"janus\": \"keepalive\"}"
#define JANUS_MSG_STREAMING_PLUGIN_CREATE "{\"transaction\": \"ciao\", \"janus\": \"attach\", \"plugin\":\"janus.plugin.streaming\"}"
#define JANUS_MSG_VIDEOROOM_PLUGIN_CREATE "{\"transaction\": \"ciao\", \"janus\": \"attach\", \"plugin\":\"janus.plugin.videoroom\"}"
#define JANUS_MSG_SESSION_CREATE "{\"transaction\": \"uniq4\", \"janus\": \"create\"}"
#define JANUS_MSG_SESSION_KEEPALIVE "{\"transaction\": \"uniq3\", \"janus\": \"keepalive\"}"
#define JANUS_MSG_STREAMING_PLUGIN_CREATE "{\"transaction\": \"uniq1\", \"janus\": \"attach\", \"plugin\":\"janus.plugin.streaming\"}"
#define JANUS_MSG_VIDEOROOM_PLUGIN_CREATE "{\"transaction\": \"uniq2\", \"janus\": \"attach\", \"plugin\":\"janus.plugin.videoroom\"}"


struct janus_instance {
Expand Down Expand Up @@ -472,7 +472,7 @@ int8_t janus_instance_create_streaming_point(struct janus_instance const * janus
struct mg_connection * conn;
int8_t res = -1;
char * uri;
char * fmt = "{\"transaction\":\"random_str\",\"janus\":\"message\",\"body\":{\"request\":\"create\",\"type\":\"rtp\",\
char * fmt = "{\"transaction\":\"%d\",\"janus\":\"message\",\"body\":{\"request\":\"create\",\"type\":\"rtp\",\
\"audio\":true,\"audioport\":%"PRId16",\"audiopt\":111,\"audiortpmap\":\"opus/48000/2\",\
\"video\":true,\"videoport\":%"PRId16",\"videopt\":98,\"videortpmap\":\"VP8/90000\"}}";
char buff[280];
Expand All @@ -483,7 +483,7 @@ int8_t janus_instance_create_streaming_point(struct janus_instance const * janus
uri = janus_instance_streaming_handle_path(janus);
if (uri)
{
sprintf(buff, fmt, audio_port, video_port);
sprintf(buff, fmt, rand(), audio_port, video_port);
debug("Conctating Janus to create a new mountpoint\n");
conn = mg_connect_http(janus->mongoose_srv, janus_instance_streaming_point_handler, uri, NULL, buff);
if (conn)
Expand All @@ -506,15 +506,15 @@ int8_t janus_instance_destroy_streaming_point(struct janus_instance const * janu
struct mg_connection * conn;
int8_t res = -1;
char * uri;
char * fmt = "{\"transaction\":\"random_str\",\"janus\":\"message\",\"body\":{\"request\":\"destroy\",\"id\": %"PRId64"}}";
char * fmt = "{\"transaction\":\"%d\",\"janus\":\"message\",\"body\":{\"request\":\"destroy\",\"id\": %"PRId64"}}";
char buff[120];

if (janus && mp_id)
{
uri = janus_instance_streaming_handle_path(janus);
if (uri)
{
sprintf(buff, fmt, mp_id);
sprintf(buff, fmt, rand(), mp_id);
conn = mg_connect_http(janus->mongoose_srv, janus_instance_generic_handler, uri, NULL, buff);
if (conn)
res = 0;
Expand All @@ -529,7 +529,7 @@ int8_t janus_instance_create_videoroom(struct janus_instance const * janus, cons
struct mg_connection * conn;
int8_t res = -1;
char * uri;
char * fmt = "{\"transaction\":\"random_str\",\"janus\":\"message\",\"body\":{\"request\":\"create\",\"room\":%s,\"publishers\":1,\"bitrate\":2048000,\"record\":false,\"description\":\"Room %s\",\"fir_freq\":5,\"audiocodec\":\"opus\",\"videocodec\":\"vp8\"}}";
char * fmt = "{\"transaction\":\"%d\",\"janus\":\"message\",\"body\":{\"request\":\"create\",\"room\":%s,\"publishers\":1,\"bitrate\":2048000,\"record\":false,\"description\":\"Room %s\",\"fir_freq\":5,\"audiocodec\":\"opus\",\"videocodec\":\"vp8\"}}";

char buff[280];
void ** data;
Expand All @@ -539,7 +539,7 @@ int8_t janus_instance_create_videoroom(struct janus_instance const * janus, cons
uri = janus_instance_videoroom_handle_path(janus);
if (uri)
{
sprintf(buff, fmt, room_id, room_id);
sprintf(buff, fmt, rand(), room_id, room_id);
debug("Conctating Janus to create a new video room\n");
conn = mg_connect_http(janus->mongoose_srv, janus_instance_videoroom_creation_handler, uri, NULL, buff);
if (conn)
Expand All @@ -561,15 +561,15 @@ int8_t janus_instance_destroy_videoroom(struct janus_instance const * janus, con
struct mg_connection * conn;
int8_t res = -1;
char * uri;
char * fmt = "{\"transaction\":\"random_str\",\"janus\":\"message\",\"body\":{\"request\":\"destroy\",\"room\": %s}}";
char * fmt = "{\"transaction\":\"%d\",\"janus\":\"message\",\"body\":{\"request\":\"destroy\",\"room\": %s}}";
char buff[120];

if (janus && room_id)
{
uri = janus_instance_videoroom_handle_path(janus);
if (uri)
{
sprintf(buff, fmt, room_id);
sprintf(buff, fmt, rand(), room_id);
conn = mg_connect_http(janus->mongoose_srv, janus_instance_generic_handler, uri, NULL, buff);
if (conn)
res = 0;
Expand All @@ -584,7 +584,7 @@ int8_t janus_instance_forward_rtp(struct janus_instance const * janus, const cha
struct mg_connection * conn;
int8_t res = -1;
char * uri;
char * fmt = "{\"transaction\":\"random_str\",\"janus\":\"message\",\"body\":{\"request\":\"rtp_forward\",\"room\":%s,\"publisher_id\":%"PRId64", \"host\": \"%s\",\"audio_port\":%"PRId16",\"video_port\":%"PRId16",\"audio_pt\":111,\"video_pt\":98}}";
char * fmt = "{\"transaction\":\"%d\",\"janus\":\"message\",\"body\":{\"request\":\"rtp_forward\",\"room\":%s,\"publisher_id\":%"PRId64", \"host\": \"%s\",\"audio_port\":%"PRId16",\"video_port\":%"PRId16",\"audio_pt\":111,\"video_pt\":98}}";

char buff[280];

Expand All @@ -593,7 +593,7 @@ int8_t janus_instance_forward_rtp(struct janus_instance const * janus, const cha
uri = janus_instance_videoroom_handle_path(janus);
if (uri)
{
sprintf(buff, fmt, room_id, participant_id, rtp_dest, audio_port, video_port);
sprintf(buff, fmt, rand(), room_id, participant_id, rtp_dest, audio_port, video_port);
debug("Conctating Janus to create a new video room\n");
conn = mg_connect_http(janus->mongoose_srv, janus_instance_generic_handler, uri, NULL, buff);
if (conn)
Expand Down

0 comments on commit 0ff046b

Please sign in to comment.