Revision 0bfdcc3a

View differences:

.gitignore
2 2
*.o
3 3
*.test
4 4
peerstreamer-ng
5
*.sdp
Public/assets/psng.js
1
function response_channel(ch)
2
{
3
	set_state(ch.name);
4
	var v = document.getElementById("vlc");
5
	v.playlist.playItem(vlc.playlist.add(ch.sdpfile));
6
}
7

  
8
function set_state(s)
9
{
10
	var t = document.getElementById("player-title");
11
	t.innerHTML = s;
12
}
13

  
14
function request_channel(ch)
15
{
16
	var xhttp = new XMLHttpRequest();
17
	xhttp.onreadystatechange = function() {
18
		if (this.readyState == 4 && this.status == 200) {
19
			set_state(this.responseText);
20
			var ch = JSON.parse(this.responseText);
21
			response_channel(ch);
22
		}
23
		if (this.readyState == 4 && this.status != 200) {
24
			set_state("<An error occurred with channel>");
25
		}
26
	};
27
	var id = Math.random().toString(36).substr(2, 8);
28
	xhttp.open("POST", "/channels/" + id, true);
29
	xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
30
	var params = "ipaddr=" + encodeURIComponent(ch.ipaddr) + "&port=" + encodeURIComponent(ch.port)
31
	xhttp.send(params);
32
}
33

  
1 34
function update_channels(chs)
2 35
{
3 36
	var list = document.getElementById("channel-list");
......
6 39
	}
7 40
	for (el in chs) {
8 41
		var node = document.createElement("LI");
9
		node.className="list-group-item";
42
		node.className="list-group-item btn btn-default";
10 43
		var textnode = document.createTextNode(chs[el].name);
11 44
		node.appendChild(textnode);   
12 45
		list.appendChild(node);   
46
		node.onclick = function(){request_channel(chs[el]);}
13 47
	}
14 48
}
15 49

  
Public/player.html
42 42
	<div class="row center-block">
43 43
		<div class="col-md-10">
44 44
			<div class="row center-block">
45
				<h2 class="text-center">&lt;Pick a channel from the list&gt;</h2>
45
				<h2 id="player-title" class="text-center">&lt;Pick a channel from the list&gt;</h2>
46 46
			</div>
47 47
			<div id="vlc-plugin" class="row text-center" >
48 48
				<embed pluginspage="http://www.videolan.org"
......
52 52
					height="480"
53 53
					name="vlc" id="vlc"
54 54
					autoplay="true" allowfullscreen="true" 
55
					target="channel.sdp">
56
				</embed>
55
					target="channel.sdp"/>
57 56
			</div>
58 57
		</div>
59 58
		<div class="col-md-2">
peerstreamer-ng.c
53 53
		}
54 54
}
55 55

  
56
void mg_request_decode(char * buff, int buff_len, const struct http_message *hm)
57
{
58
	size_t i = 0;
59

  
60
	if (buff_len - i -2 > hm->method.len)
61
	{
62
		memmove(buff + i, hm->method.p, hm->method.len);
63
		i += hm->method.len;
64
	}
65
	buff[i++] = ' ';
66
	if (buff_len - i -2 > hm->uri.len)
67
	{
68
		memmove(buff + i, hm->uri.p, hm->uri.len);
69
		i += hm->uri.len;
70
	}
71
	buff[i++] = ' ';
72
	if (buff_len - i -1 > hm->query_string.len)
73
	{
74
		memmove(buff + i, hm->query_string.p, hm->query_string.len);
75
		i += hm->query_string.len;
76
	}
77
	buff[i] = '\0';
78
}
79

  
56 80
void ev_handler(struct mg_connection *nc, int ev, void *ev_data)
57 81
{
58 82
	struct context *c = nc->user_data;
59 83
	struct http_message *hm;
84
	char buff[80];
60 85

  
61 86
	switch (ev) {
62 87
		case MG_EV_HTTP_REQUEST:
63 88
			hm  = (struct http_message *) ev_data;
89
			debug("Received a request:\n");
90
			mg_request_decode(buff, 80, hm);
91
			debug("\t%s\n", buff);
64 92
			// Try to call a path handler. If it fails serve
65 93
			// public contents
66 94
			if(router_handle(c->router, nc, hm))
src/path_handlers.c
92 92
			debug("Streamer instance created\n");
93 93
			sdpuri = sdpfile_create(c, ch, ps);
94 94
			mg_printf(nc, "%s", "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
95
			mg_printf_http_chunk(nc, "{id=%s,sdpfile=%s}", id, sdpuri);
95
			mg_printf_http_chunk(nc, "{\"id\":\"%s\",\"name\":\"%s\",\"sdpfile\":\"%s\"}", id, ch->name, sdpuri);
96 96
			mg_send_http_chunk(nc, "", 0); /* Send empty chunk, the end of response */
97 97
			free(sdpuri);
98 98
		} else {
src/sdpfile.c
118 118
{
119 119
	struct mg_connection * conn;
120 120
	struct pssdpfile * psdp;
121
	char sdpfile[MAX_SDPFILENAME_LENGTH];
121 122

  
122 123
	psdp = malloc(sizeof(struct pssdpfile));
123 124
	psdp->ps = ps;
124 125
	snprintf(psdp->path, MAX_PATH_LENGTH, "%s/%s.sdp", c->http_opts.document_root, pstreamer_id(ps));
126
	snprintf(sdpfile, MAX_SDPFILENAME_LENGTH, "%s.sdp", pstreamer_id(ps));
125 127

  
126 128
	conn = mg_connect_http(c->mongoose_srv, sdpfile_handler, ch->sdpfile, NULL, NULL);
127 129
	conn->user_data = (void *) psdp;
128 130

  
129
	return strdup(psdp->path);
131
	return strdup(sdpfile);
130 132
}

Also available in: Unified diff