Revision 47576630

View differences:

html/echotest.js
27 27
			janus = new Janus(
28 28
				{
29 29
					server: server,
30
					//~ iceServers: [{url: "turn:janususer@143.225.229.166:3478", credential: "januspwd"}],
31
					//~ iceServers: [{url: "turn:janususer@143.225.229.166:443?transport=tcp", credential: "januspwd"}],
32
					//~ iceServers: [{url: "turns:janususer@143.225.229.166:443?transport=tcp", credential: "januspwd"}],
30
					// No "iceServers" is provided, meaning janus.js will use a default STUN server
31
					// Here are some examples of how an iceServers field may look like to support TURN
32
					// 		iceServers: [{url: "turn:janususer@yourturnserver.com:3478", credential: "januspwd"}],
33
					// 		iceServers: [{url: "turn:janususer@yourturnserver.com:443?transport=tcp", credential: "januspwd"}],
34
					// 		iceServers: [{url: "turns:janususer@yourturnserver.com:443?transport=tcp", credential: "januspwd"}],
33 35
					success: function() {
34 36
						// Attach to echo test plugin
35 37
						janus.attach(
plugins/janus_audiobridge.c
541 541
		}
542 542
		const char *request_text = json_string_value(request);
543 543
		json_t *event = NULL;
544
		if(!strcasecmp(request_text, "join")) {
544
		if(!strcasecmp(request_text, "create")) {
545
			/* Create a new audiobridge */
546
			JANUS_PRINT("Creating a new audiobridge\n");
547
			json_t *desc = json_object_get(root, "description");
548
			if(desc && !json_is_string(desc)) {
549
				JANUS_DEBUG("JSON error: invalid element (desc)\n");
550
				sprintf(error_cause, "JSON error: invalid element (desc)");
551
				goto error;
552
			}
553
			json_t *sampling = json_object_get(root, "sampling");
554
			if(sampling && !json_is_integer(sampling)) {
555
				JANUS_DEBUG("JSON error: invalid element (sampling)\n");
556
				sprintf(error_cause, "JSON error: invalid element (sampling)");
557
				goto error;
558
			}
559
			json_t *record = json_object_get(root, "record");
560
			if(record && !json_is_boolean(record)) {
561
				JANUS_DEBUG("JSON error: invalid element (record)\n");
562
				sprintf(error_cause, "JSON error: invalid value (record)");
563
				goto error;
564
			}
565
			/* Create the audio bridge room */
566
			janus_audiobridge_room *audiobridge = calloc(1, sizeof(janus_audiobridge_room));
567
			if(audiobridge == NULL) {
568
				JANUS_DEBUG("Memory error!\n");
569
				sprintf(error_cause, "Memory error");
570
				goto error;
571
			}
572
			/* Generate a random ID */
573
			guint64 room_id = 0;
574
			while(room_id == 0) {
575
				room_id = g_random_int();
576
				if(g_hash_table_lookup(rooms, GUINT_TO_POINTER(room_id)) != NULL) {
577
					/* Room ID already taken, try another one */
578
					room_id = 0;
579
				}
580
			}
581
			audiobridge->room_id = room_id;
582
			char *description = NULL;
583
			if(desc != NULL) {
584
				description = g_strdup(json_string_value(desc));
585
			} else {
586
				char roomname[255];
587
				sprintf(roomname, "Room %"SCNu64"", audiobridge->room_id);
588
				description = g_strdup(roomname);
589
			}
590
			if(description == NULL) {
591
				JANUS_DEBUG("Memory error!\n");
592
				continue;
593
			}
594
			audiobridge->room_name = description;
595
			if(sampling)
596
				audiobridge->sampling_rate = json_integer_value(sampling);
597
			else
598
				audiobridge->sampling_rate = 16000;
599
			if(audiobridge->sampling_rate != 16000) {
600
				JANUS_DEBUG("We currently only support 16kHz (wideband) as a sampling rate for audio rooms, changing %"SCNu32" to 16000...\n", audiobridge->sampling_rate);
601
				audiobridge->sampling_rate = 16000;
602
			}
603
			audiobridge->record = FALSE;
604
			if(record && json_is_true(record))
605
				audiobridge->record = TRUE;
606
			audiobridge->recording = NULL;
607
			audiobridge->destroy = 0;
608
			audiobridge->participants = g_hash_table_new(NULL, NULL);
609
			janus_mutex_init(&audiobridge->mutex);
610
			g_hash_table_insert(rooms, GUINT_TO_POINTER(audiobridge->room_id), audiobridge);
611
			JANUS_PRINT("Created audiobridge: %"SCNu64" (%s)\n", audiobridge->room_id, audiobridge->room_name);
612
			/* We need a thread for the mix */
613
			g_thread_new("audiobridge mixer thread", &janus_audiobridge_mixer_thread, audiobridge);
614
			/* Show updated rooms list */
615
			GList *rooms_list = g_hash_table_get_values(rooms);
616
			GList *r = rooms_list;
617
			while(r) {
618
				janus_audiobridge_room *ar = (janus_audiobridge_room *)r->data;
619
				JANUS_PRINT("  ::: [%"SCNu64"][%s] %"SCNu32" (%s be recorded)\n",
620
					ar->room_id, ar->room_name, ar->sampling_rate, ar->record ? "will" : "will NOT");
621
				r = r->next;
622
			}
623
			g_list_free(rooms_list);
624
			/* Send info back */
625
			event = json_object();
626
			json_object_set(event, "audiobridge", json_string("created"));
627
			json_object_set(event, "room", json_integer(audiobridge->room_id));
628
		} else if(!strcasecmp(request_text, "join")) {
545 629
			JANUS_PRINT("Configuring new participant\n");
546 630
			json_t *room = json_object_get(root, "room");
547 631
			if(!room || !json_is_integer(room)) {
plugins/janus_videoroom.c
568 568
		}
569 569
		const char *request_text = json_string_value(request);
570 570
		json_t *event = NULL;
571
		if(!strcasecmp(request_text, "create")) {
572
			/* Create a new videoroom */
573
			JANUS_PRINT("Creating a new videoroom\n");
574
			json_t *desc = json_object_get(root, "description");
575
			if(desc && !json_is_string(desc)) {
576
				JANUS_DEBUG("JSON error: invalid element (desc)\n");
577
				sprintf(error_cause, "JSON error: invalid element (desc)");
578
				goto error;
579
			}
580
			json_t *bitrate = json_object_get(root, "bitrate");
581
			if(bitrate && !json_is_integer(bitrate)) {
582
				JANUS_DEBUG("JSON error: invalid element (bitrate)\n");
583
				sprintf(error_cause, "JSON error: invalid element (bitrate)");
584
				goto error;
585
			}
586
			json_t *publishers = json_object_get(root, "publishers");
587
			if(publishers && !json_is_integer(publishers)) {
588
				JANUS_DEBUG("JSON error: invalid element (publishers)\n");
589
				sprintf(error_cause, "JSON error: invalid element (publishers)");
590
				goto error;
591
			}
592
			/* Create the audio bridge room */
593
			janus_videoroom *videoroom = calloc(1, sizeof(janus_videoroom));
594
			if(videoroom == NULL) {
595
				JANUS_DEBUG("Memory error!\n");
596
				sprintf(error_cause, "Memory error");
597
				goto error;
598
			}
599
			/* Generate a random ID */
600
			guint64 room_id = 0;
601
			while(room_id == 0) {
602
				room_id = g_random_int();
603
				if(g_hash_table_lookup(rooms, GUINT_TO_POINTER(room_id)) != NULL) {
604
					/* Room ID already taken, try another one */
605
					room_id = 0;
606
				}
607
			}
608
			videoroom->room_id = room_id;
609
			char *description = NULL;
610
			if(desc != NULL) {
611
				description = g_strdup(json_string_value(desc));
612
			} else {
613
				char roomname[255];
614
				sprintf(roomname, "Room %"SCNu64"", videoroom->room_id);
615
				description = g_strdup(roomname);
616
			}
617
			if(description == NULL) {
618
				JANUS_DEBUG("Memory error!\n");
619
				continue;
620
			}
621
			videoroom->room_name = description;
622
			videoroom->max_publishers = 3;	/* FIXME How should we choose a default? */
623
			if(publishers)
624
				videoroom->max_publishers = json_integer_value(publishers);
625
			if(videoroom->max_publishers < 0)
626
				videoroom->max_publishers = 3;	/* FIXME How should we choose a default? */
627
			videoroom->bitrate = 0;
628
			if(bitrate)
629
				videoroom->bitrate = json_integer_value(bitrate);
630
			videoroom->destroy = 0;
631
			videoroom->participants = g_hash_table_new(NULL, NULL);
632
			g_hash_table_insert(rooms, GUINT_TO_POINTER(videoroom->room_id), videoroom);
633
			JANUS_PRINT("Created videoroom: %"SCNu64" (%s)\n", videoroom->room_id, videoroom->room_name);
634
			/* Show updated rooms list */
635
			GList *rooms_list = g_hash_table_get_values(rooms);
636
			GList *r = rooms_list;
637
			while(r) {
638
				janus_videoroom *vr = (janus_videoroom *)r->data;
639
				JANUS_PRINT("  ::: [%"SCNu64"][%s] %"SCNu64", max %d publishers\n", vr->room_id, vr->room_name, vr->bitrate, vr->max_publishers);
640
				r = r->next;
641
			}
642
			g_list_free(rooms_list);
643
			/* Send info back */
644
			event = json_object();
645
			json_object_set(event, "videoroom", json_string("created"));
646
			json_object_set(event, "room", json_integer(videoroom->room_id));
647
		} else
571 648
		/* What kind of participant is this session referring to? */
572 649
		if(session->participant_type == janus_videoroom_p_type_none) {
573 650
			JANUS_PRINT("Configuring new participant\n");

Also available in: Unified diff