forked from meetecho/janus-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjanus_videoroom.c
7239 lines (7109 loc) · 323 KB
/
janus_videoroom.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*! \file janus_videoroom.c
* \author Lorenzo Miniero <lorenzo@meetecho.com>
* \copyright GNU General Public License v3
* \brief Janus VideoRoom plugin
* \details Check the \ref videoroom for more details.
*
* \ingroup plugins
* \ref plugins
*
* \page videoroom VideoRoom plugin documentation
* This is a plugin implementing a videoconferencing SFU
* (Selective Forwarding Unit) for Janus, that is an audio/video router.
* This means that the plugin implements a virtual conferencing room peers
* can join and leave at any time. This room is based on a Publish/Subscribe
* pattern. Each peer can publish his/her own live audio/video feeds: this
* feed becomes an available stream in the room the other participants can
* attach to. This means that this plugin allows the realization of several
* different scenarios, ranging from a simple webinar (one speaker, several
* watchers) to a fully meshed video conference (each peer sending and
* receiving to and from all the others).
*
* Considering that this plugin allows for several different WebRTC PeerConnections
* to be on at the same time for the same peer (specifically, each peer
* potentially has 1 PeerConnection on for publishing and N on for subscriptions
* from other peers), each peer may need to attach several times to the same
* plugin for every stream: this means that each peer needs to have at least one
* handle active for managing its relation with the plugin (joining a room,
* leaving a room, muting/unmuting, publishing, receiving events), and needs
* to open a new one each time he/she wants to subscribe to a feed from
* another publisher participant. The handle used for a subscription,
* however, would be logically a "slave" to the master one used for
* managing the room: this means that it cannot be used, for instance,
* to unmute in the room, as its only purpose would be to provide a
* context in which creating the recvonly PeerConnection for the
* subscription to an active publisher participant.
*
* \note Work is going on to implement SSRC multiplexing (Unified Plan),
* meaning that in the future you'll be able to use the same
* Janus handle/VideoRoom subscriber/PeerConnection to receive multiple
* publishers at the same time.
*
* Rooms to make available are listed in the plugin configuration file.
* A pre-filled configuration file is provided in \c conf/janus.plugin.videoroom.jcfg
* and includes a demo room for testing. The same plugin is also used
* dynamically (that is, with rooms created on the fly via API) in the
* Screen Sharing demo as well.
*
* To add more rooms or modify the existing one, you can use the following
* syntax:
*
* \verbatim
room-<unique room ID>: {
description = This is my awesome room
is_private = true|false (private rooms don't appear when you do a 'list' request)
secret = <optional password needed for manipulating (e.g. destroying) the room>
pin = <optional password needed for joining the room>
require_pvtid = true|false (whether subscriptions are required to provide a valid
a valid private_id to associate with a publisher, default=false)
publishers = <max number of concurrent senders> (e.g., 6 for a video
conference or 1 for a webinar, default=3)
bitrate = <max video bitrate for senders> (e.g., 128000)
fir_freq = <send a FIR to publishers every fir_freq seconds> (0=disable)
audiocodec = opus|g722|pcmu|pcma|isac32|isac16 (audio codec to force on publishers, default=opus
can be a comma separated list in order of preference, e.g., opus,pcmu)
videocodec = vp8|vp9|h264 (video codec to force on publishers, default=vp8
can be a comma separated list in order of preference, e.g., vp9,vp8,h264)
opus_fec = true|false (whether inband FEC must be negotiated; only works for Opus, default=false)
video_svc = true|false (whether SVC support must be enabled; only works for VP9, default=false)
audiolevel_ext = true|false (whether the ssrc-audio-level RTP extension must be
negotiated/used or not for new publishers, default=true)
audiolevel_event = true|false (whether to emit event to other users or not)
audio_active_packets = 100 (number of packets with audio level, default=100, 2 seconds)
audio_level_average = 25 (average value of audio level, 127=muted, 0='too loud', default=25)
videoorient_ext = true|false (whether the video-orientation RTP extension must be
negotiated/used or not for new publishers, default=true)
playoutdelay_ext = true|false (whether the playout-delay RTP extension must be
negotiated/used or not for new publishers, default=true)
transport_wide_cc_ext = true|false (whether the transport wide CC RTP extension must be
negotiated/used or not for new publishers, default=true)
record = true|false (whether this room should be recorded, default=false)
rec_dir = <folder where recordings should be stored, when enabled>
notify_joining = true|false (optional, whether to notify all participants when a new
participant joins the room. The Videoroom plugin by design only notifies
new feeds (publishers), and enabling this may result extra notification
traffic. This flag is particularly useful when enabled with \c require_pvtid
for admin to manage listening only participants. default=false)
}
\endverbatim
*
* Note that recording will work with all codecs except iSAC.
*
* \section sfuapi Video Room API
*
* The Video Room API supports several requests, some of which are
* synchronous and some asynchronous. There are some situations, though,
* (invalid JSON, invalid request) which will always result in a
* synchronous error response even for asynchronous requests.
*
* \c create , \c destroy , \c edit , \c exists, \c list, \c allowed, \c kick and
* and \c listparticipants are synchronous requests, which means you'll
* get a response directly within the context of the transaction.
* \c create allows you to create a new video room dynamically, as an
* alternative to using the configuration file; \c edit allows you to
* dynamically edit some room properties (e.g., the PIN); \c destroy removes a
* video room and destroys it, kicking all the users out as part of the
* process; \c exists allows you to check whether a specific video room
* exists; finally, \c list lists all the available rooms, while \c
* listparticipants lists all the active (as in currentòy publishing
* something) participants of a specific room and their details.
*
* The \c join , \c joinandconfigure , \c configure , \c publish ,
* \c unpublish , \c start , \c pause , \c switch and \c leave
* requests instead are all asynchronous, which
* means you'll get a notification about their success or failure in
* an event. \c join allows you to join a specific video room, specifying
* whether that specific PeerConnection will be used for publishing or
* watching; \c configure can be used to modify some of the participation
* settings (e.g., bitrate cap); \c joinandconfigure combines the previous
* two requests in a single one (just for publishers); \c publish can be
* used to start sending media to broadcast to the other participants,
* while \c unpublish does the opposite; \c start allows you to start
* receiving media from a publisher you've subscribed to previously by
* means of a \c join , while \c pause pauses the delivery of the media;
* the \c switch request can be used to change the source of the media
* flowing over a specific PeerConnection (e.g., I was watching Alice,
* I want to watch Bob now) without having to create a new handle for
* that; \c finally, \c leave allows you to leave a video room for good
* (or, in the case of viewers, definitely closes a subscription).
*
* \c create can be used to create a new video room, and has to be
* formatted as follows:
*
\verbatim
{
"request" : "create",
"room" : <unique numeric ID, optional, chosen by plugin if missing>,
"permanent" : <true|false, whether the room should be saved in the config file, default=false>,
"description" : "<pretty name of the room, optional>",
"secret" : "<password required to edit/destroy the room, optional>",
"pin" : "<password required to join the room, optional>",
"is_private" : <true|false, whether the room should appear in a list request>,
"allowed" : [ array of string tokens users can use to join this room, optional],
...
}
\endverbatim
*
* For the sake of brevity, not all of the available settings are listed
* here. You can refer to the name of the properties in the configuration
* file as a reference, as the ones used to programmatically create a new
* room are exactly the same.
*
* A successful creation procedure will result in a \c created response:
*
\verbatim
{
"videoroom" : "created",
"room" : <unique numeric ID>,
"permanent" : <true if saved to config file, false if not>
}
\endverbatim
*
* If you requested a permanent room but a \c false value is returned
* instead, good chances are that there are permission problems.
*
* An error instead (and the same applies to all other requests, so this
* won't be repeated) would provide both an error code and a more verbose
* description of the cause of the issue:
*
\verbatim
{
"videoroom" : "event",
"error_code" : <numeric ID, check Macros below>,
"error" : "<error description as a string>"
}
\endverbatim
*
* Notice that, in general, all users can create rooms. If you want to
* limit this functionality, you can configure an admin \c admin_key in
* the plugin settings. When configured, only "create" requests that
* include the correct \c admin_key value in an "admin_key" property
* will succeed, and will be rejected otherwise. Notice that you can
* optionally extend this functionality to RTP forwarding as well, in
* order to only allow trusted clients to use that feature.
*
* Once a room has been created, you can still edit some (but not all)
* of its properties using the \c edit request. This allows you to modify
* the room description, secret, pin and whether it's private or not: you
* won't be able to modify other more static properties, like the room ID,
* the sampling rate, the extensions-related stuff and so on. If you're
* interested in changing the ACL, instead, check the \c allowed message.
* An \c edit request has to be formatted as follows:
*
\verbatim
{
"request" : "edit",
"room" : <unique numeric ID of the room to edit>,
"secret" : "<room secret, mandatory if configured>",
"new_description" : "<new pretty name of the room, optional>",
"new_secret" : "<new password required to edit/destroy the room, optional>",
"new_pin" : "<new password required to join the room, optional>",
"new_is_private" : <true|false, whether the room should appear in a list request>,
"new_require_pvtid" : <true|false, whether the room should require private_id from subscribers>,
"new_bitrate" : <new bitrate cap to force on all publishers (except those with custom overrides)>,
"new_fir_freq" : <new period for regular PLI keyframe requests to publishers>,
"new_publishers" : <new cap on the number of concurrent active WebRTC publishers>,
"permanent" : <true|false, whether the room should be also removed from the config file, default=false>
}
\endverbatim
*
* A successful edit procedure will result in an \c edited response:
*
\verbatim
{
"videoroom" : "edited",
"room" : <unique numeric ID>
}
\endverbatim
*
* On the other hand, \c destroy can be used to destroy an existing video
* room, whether created dynamically or statically, and has to be
* formatted as follows:
*
\verbatim
{
"request" : "destroy",
"room" : <unique numeric ID of the room to destroy>,
"secret" : "<room secret, mandatory if configured>",
"permanent" : <true|false, whether the room should be also removed from the config file, default=false>
}
\endverbatim
*
* A successful destruction procedure will result in a \c destroyed response:
*
\verbatim
{
"videoroom" : "destroyed",
"room" : <unique numeric ID>
}
\endverbatim
*
* This will also result in a \c destroyed event being sent to all the
* participants in the video room, which will look like this:
*
\verbatim
{
"videoroom" : "destroyed",
"room" : <unique numeric ID of the destroyed room>
}
\endverbatim
*
* You can check whether a room exists using the \c exists request,
* which has to be formatted as follows:
*
\verbatim
{
"request" : "exists",
"room" : <unique numeric ID of the room to check>
}
\endverbatim
*
* A successful request will result in a \c success response:
*
\verbatim
{
"videoroom" : "success",
"room" : <unique numeric ID>,
"exists" : <true|false>
}
\endverbatim
*
* You can configure whether to check tokens or add/remove people who can join
* a room using the \c allowed request, which has to be formatted as follows:
*
\verbatim
{
"request" : "allowed",
"secret" : "<room secret, mandatory if configured>",
"action" : "enable|disable|add|remove",
"room" : <unique numeric ID of the room to update>,
"allowed" : [
// Array of strings (tokens users might pass in "join", only for add|remove)
]
}
\endverbatim
*
* A successful request will result in a \c success response:
*
\verbatim
{
"videoroom" : "success",
"room" : <unique numeric ID>,
"allowed" : [
// Updated, complete, list of allowed tokens (only for enable|add|remove)
]
}
\endverbatim
*
* If you're the administrator of a room (that is, you created it and have access
* to the secret) you can kick participants using the \c kick request. Notice
* that this only kicks the user out of the room, but does not prevent them from
* re-joining: to ban them, you need to first remove them from the list of
* authorized users (see \c allowed request) and then \c kick them. The \c kick
* request has to be formatted as follows:
*
\verbatim
{
"request" : "kick",
"secret" : "<room secret, mandatory if configured>",
"room" : <unique numeric ID of the room>,
"id" : <unique numeric ID of the participant to kick>
}
\endverbatim
*
* A successful request will result in a \c success response:
*
\verbatim
{
"videoroom" : "success",
}
\endverbatim
*
* To get a list of the available rooms (excluded those configured or
* created as private rooms) you can make use of the \c list request,
* which has to be formatted as follows:
*
\verbatim
{
"request" : "list"
}
\endverbatim
*
* A successful request will produce a list of rooms in a \c success response:
*
\verbatim
{
"videoroom" : "success",
"rooms" : [ // Array of room objects
{ // Room #1
"room" : <unique numeric ID>,
"description" : "<Name of the room>",
"pin_required" : <true|false, whether a PIN is required to join this room>,
"max_publishers" : <how many publishers can actually publish via WebRTC at the same time>,
"bitrate" : <bitrate cap that should be forced (via REMB) on all publishers by default>,
"bitrate_cap" : <true|false, whether the above cap should act as a limit to dynamic bitrate changes by publishers>,
"fir_freq" : <how often a keyframe request is sent via PLI/FIR to active publishers>,
"audiocodec" : "<comma separated list of allowed audio codecs>",
"videocodec" : "<comma separated list of allowed video codecs>",
"record" : <true|false, whether the room is being recorded>,
"record_dir" : "<if recording, the path where the .mjr files are being saved>",
"num_participants" : <count of the participants (publishers, active or not; not subscribers)>
},
// Other rooms
]
}
\endverbatim
*
* To get a list of the participants in a specific room, instead, you
* can make use of the \c listparticipants request, which has to be
* formatted as follows:
*
\verbatim
{
"request" : "listparticipants",
"room" : <unique numeric ID of the room>
}
\endverbatim
*
* A successful request will produce a list of participants in a
* \c participants response:
*
\verbatim
{
"videoroom" : "participants",
"room" : <unique numeric ID of the room>,
"participants" : [ // Array of participant objects
{ // Participant #1
"id" : <unique numeric ID of the participant>,
"display" : "<display name of the participant, if any; optional>",
"talking" : <true|false, whether user is talking or not (only if audio levels are used)>,
"internal_audio_ssrc" : <audio SSRC used internally for this active publisher>,
"internal_video_ssrc" : <video SSRC used internally for this active publisher>
},
// Other participants
]
}
\endverbatim
*
* This covers almost all the synchronous requests. All the asynchronous requests,
* plus a couple of additional synchronous requests we'll cover later, refer
* to participants instead, namely on how they can publish, subscribe, or
* more in general manage the media streams they may be sending or receiving.
*
* Considering the different nature of publishers and subscribers in the room,
* and more importantly how you establish PeerConnections in the respective
* cases, their API requests are addressed in separate subsections.
*
* \subsection vroompub VideoRoom Publishers
*
* In a VideoRoom, publishers are those participant handles that are able
* (although may choose not to, more on this later) publish media in the
* room, and as such become feeds that you can subscribe to.
*
* To specify a handle will be associated with a publisher, you must use
* the \c join request with \c ptype set to \c publisher (note that, as it
* will be explained later, you can also use \c joinandconfigure for the
* purpose). The exact syntax of the request is the following:
*
\verbatim
{
"request" : "join",
"ptype" : "publisher",
"room" : <unique ID of the room to join>,
"id" : <unique ID to register for the publisher; optional, will be chosen by the plugin if missing>,
"display" : "<display name for the publisher; optional>",
"token" : "<invitation token, in case the room has an ACL; optional>"
}
\endverbatim
*
* This will add the user to the list of participants in the room, although
* in a non-active role for the time being. Anyway, this participation
* allows the user to receive notifications about several aspects of the
* room on the related handle (including streams as they become available
* and go away). As such, it can be used even just as a way to get
* notifications in a room, without the need of ever actually publishing
* any stream at all (which explains why the "publisher" role may actually
* be a bit confusing in this context).
*
* A successful \c join will result in a \c joined event, which will contain
* a list of the currently active (as in publishing via WebRTC) publishers,
* and optionally a list of passive attendees (but only if the room was
* configured with \c notify_joining set to \c TRUE ):
*
\verbatim
{
"videoroom" : "joined",
"room" : <room ID>,
"description" : <description of the room, if available>,
"id" : <unique ID of the participant>,
"private_id" : <a different unique ID associated to the participant; meant to be private>,
"publishers" : [
{
"id" : <unique ID of active publisher #1>,
"display" : "<display name of active publisher #1, if any>",
"audio_codec" : "<audio codec used by active publisher #1, if any>",
"video_codec" : "<video codec used by active publisher #1, if any>",
"simulcast" : "<true if the publisher uses simulcast (VP8 and H.264 only)>",
"talking" : <true|false, whether the publisher is talking or not (only if audio levels are used)>,
},
// Other active publishers
],
"attendees" : [ // Only present when notify_joining is set to TRUE for rooms
{
"id" : <unique ID of attendee #1>,
"display" : "<display name of attendee #1, if any>"
},
// Other attendees
]
}
\endverbatim
*
* Notice that the publishers list will of course be empty if no one is
* currently active in the room. For what concerns the \c private_id
* property, it is meant to be used by the user when they create subscriptions,
* so that the plugin can associate subscriber handles (which are typically
* anonymous) to a specific participant; they're usually optional, unless
* required by the room configuration.
*
* As explained, with a simple \c join you're not an active publisher (there
* is no WebRTC PeerConnection yet), which means that by default your presence
* is not notified to other participants. In fact, the publish/subscribe nature
* of the plugin implies that by default only active publishers are notified,
* to allow participants to subscribe to existing feeds: notifying all joins/leaves,
* even those related to who will just lurk, may be overly verbose and chatty,
* especially in large rooms. Anyway, rooms can be configured to notify those
* as well, if the \c notify_joining property is set to true: in that case,
* regular joins will be notified too, in an event formatted like this:
*
\verbatim
{
"videoroom" : "event",
"room" : <room ID>,
"joining" : {
"id" : <unique ID of the new participant>,
"display" : "<display name of the new participant, if any>"
}
}
\endverbatim
*
* If you're interested in publishing media within a room, you can do that
* with a \c publish request. This request MUST be accompanied by a JSEP
* SDP offer to negotiate a new PeerConnection. The plugin will match it
* to the room configuration (e.g., to make sure the codecs you negotiated
* are allowed in the room), and will reply with a JSEP SDP answer to
* close the circle and complete the setup of the PeerConnection. As soon
* as the PeerConnection has been establisher, the publisher will become
* active, and a new active feed other participants can subscribe to.
*
* The syntax of a \c publish request is the following:
*
\verbatim
{
"request" : "publish",
"audio" : <true|false, depending on whether or not audio should be relayed; true by default>,
"video" : <true|false, depending on whether or not video should be relayed; true by default>,
"data" : <true|false, depending on whether or not data should be relayed; true by default>,
"audiocodec" : "<audio codec to prefer among the negotiated ones; optional>",
"videocodec" : "<video codec to prefer among the negotiated ones; optional>",
"bitrate" : <bitrate cap to return via REMB; optional, overrides the global room value if present>,
"record" : <true|false, whether this publisher should be recorded or not; optional>,
"filename" : "<if recording, the base path/file to use for the recording files; optional>",
"display" : "<new display name to use in the room; optional>"
}
\endverbatim
*
* As anticipated, since this is supposed to be accompanied by a JSEP SDP
* offer describing the publisher's media streams, the plugin will negotiate
* and prepare a matching JSEP SDP answer. If successful, a \c configured
* event will be sent back, formatted like this:
*
\verbatim
{
"videoroom" : "event",
"configured" : "ok"
}
\endverbatim
*
* This event will be accompanied by the prepared JSEP SDP answer.
*
* Notice that you can also use \c configure as a request instead of
* \c publish to start publishing. The two are functionally equivalent
* for publishing, but from a semantic perspective \c publish is the
* right message to send when publishing. The \c configure request, as
* it will be clearer later, can also be used to update some properties
* of the publisher session: in this case the \c publish request can NOT
* be used, as it can only be invoked to publish, and will fail if you're
* already publishing something.
*
* As an additional note, notice that you can also join and publish in
* a single request, which is useful in case you're not interested in
* first join as a passive attendee and only later publish something,
* but want to publish something right away. In this case you can use
* the \c joinandconfigure request, which as you can imagine combines
* the properties of both \c join and \c publish in a single request:
* the response to a \c joinandconfigure will be a \c joined event, and
* will again be accompanied by a JSEP SDP answer as usual.
*
* However you decided to publish something, as soon as the PeerConnection
* setup succeeds and the publisher becomes active, an event is sent to
* all the participants in the room with information on the new feed.
* The event must contain an array with a single element, and be formatted like this:
*
\verbatim
{
"videoroom" : "event",
"room" : <room ID>,
"publishers" : [
{
"id" : <unique ID of the new publisher>,
"display" : "<display name of the new publisher, if any>",
"audio_codec" : "<audio codec used the new publisher, if any>",
"video_codec" : "<video codec used by the new publisher, if any>",
"simulcast" : "<true if the publisher uses simulcast (VP8 and H.264 only)>",
"talking" : <true|false, whether the publisher is talking or not (only if audio levels are used)>,
}
]
}
\endverbatim
*
* To stop publishing and tear down the related PeerConnection, you can
* use the \c unpublish request, which requires no arguments as the context
* is implicit:
*
\verbatim
{
"request" : "unpublish"
}
\endverbatim
*
* This will have the plugin tear down the PeerConnection, and remove the
* publisher from the list of active streams. If successful, the response
* will look like this:
*
\verbatim
{
"videoroom" : "event",
"unpublished" : "ok"
}
\endverbatim
*
* As soon as the PeerConnection is gone, all the other participants will
* also be notified about the fact that the stream is no longer available:
*
\verbatim
{
"videoroom" : "event",
"room" : <room ID>,
"unpublished" : <unique ID of the publisher who unpublished>
}
\endverbatim
*
* Notice that the same event will also be sent whenever the publisher
* feed disappears for reasons other than an explicit \c unpublish , e.g.,
* because the handle was closed or the user lost their connection.
* Besides, notice that you can publish and unpublish multiple times
* within the context of the same publisher handle.
*
* As anticipated above, you can use a request called \c configure to
* tweak some of the properties of an active publisher session. This
* request must be formatted as follows:
*
\verbatim
{
"request" : "configure",
"audio" : <true|false, depending on whether or not audio should be relayed; true by default>,
"video" : <true|false, depending on whether or not video should be relayed; true by default>,
"data" : <true|false, depending on whether or not data should be relayed; true by default>,
"bitrate" : <bitrate cap to return via REMB; optional, overrides the global room value if present (unless bitrate_cap is set)>,
"keyframe" : <true|false, whether we should send this publisher a keyframe request>,
"record" : <true|false, whether this publisher should be recorded or not; optional>,
"filename" : "<if recording, the base path/file to use for the recording files; optional>",
"display" : "<new display name to use in the room; optional>"
}
\endverbatim
*
* As you can see, it's basically the same properties as those listed for
* \c publish . This is why both requests can be used to start publishing,
* as even in that case you configure some of the settings. If successful,
* a \c configured event will be sent back as before, formatted like this:
*
\verbatim
{
"videoroom" : "event",
"configured" : "ok"
}
\endverbatim
*
* When configuring the room to request the ssrc-audio-level RTP extension,
* ad-hoc events might be sent to all publishers if \c audiolevel_event is
* set to true. These events will have the following format:
*
\verbatim
{
"videoroom" : <"talking"|"stopped-talking", whether the publisher started or stopped talking>,
"room" : <unique numeric ID of the room the publisher is in>,
"id" : <unique numeric ID of the publisher>,
"audio-level-dBov-avg" : <average value of audio level, 127=muted, 0='too loud'>
}
\endverbatim
*
* An interesting feature VideoRoom publisher can take advantage of is
* RTP forwarding. In fact, while the main purpose of this plugin is
* getting media from WebRTC sources (publishers) and relaying it to
* WebRTC destinations (subscribers), there are actually several use
* cases and scenarios for making this media available to external,
* notnecessarily WebRTC-compliant, components. These components may
* benefit from having access to the RTP media sent by a publisher, e.g.,
* for media processing, external recording, transcoding to other
* technologies via other applications, scalability purposes or
* whatever else makes sense in this context. This is made possible by
* a request called \c rtp_forward which, as the name suggests, simply
* forwards in real-time the media sent by a publisher via RTP (plain
* or encrypted) to a remote backend.
*
* You can add a new RTP forwarder for an existing publisher using the
* \c rtp_forward request, which has to be formatted as follows:
*
\verbatim
{
"request" : "rtp_forward",
"room" : <unique numeric ID of the room the publisher is in>,
"publisher_id" : <unique numeric ID of the publisher to relay externally>,
"host" : "<host address to forward the RTP and data packets to>",
"host_family" : "<ipv4|ipv6, if we need to resolve the host address to an IP; by default, whatever we get>",
"audio_port" : <port to forward the audio RTP packets to>,
"audio_ssrc" : <audio SSRC to use to use when streaming; optional>,
"audio_pt" : <audio payload type to use when streaming; optional>,
"audio_rtcp_port" : <port to contact to receive audio RTCP feedback from the recipient; optional, and currently unused for audio>,
"video_port" : <port to forward the video RTP packets to>,
"video_ssrc" : <video SSRC to use to use when streaming; optional>,
"video_pt" : <video payload type to use when streaming; optional>,
"video_rtcp_port" : <port to contact to receive video RTCP feedback from the recipient; optional>,
"video_port_2" : <if simulcasting, port to forward the video RTP packets from the second substream/layer to>,
"video_ssrc_2" : <if simulcasting, video SSRC to use to use the second substream/layer; optional>,
"video_pt_2" : <if simulcasting, video payload type to use the second substream/layer; optional>,
"video_port_3" : <if simulcasting, port to forward the video RTP packets from the third substream/layer to>,
"video_ssrc_3" : <if simulcasting, video SSRC to use to use the third substream/layer; optional>,
"video_pt_3" : <if simulcasting, video payload type to use the third substream/layer; optional>,
"data_port" : <port to forward the datachannel messages to>,
"srtp_suite" : <length of authentication tag (32 or 80); optional>,
"srtp_crypto" : "<key to use as crypto (base64 encoded key as in SDES); optional>"
}
\endverbatim
*
* Notice that, as explained above, in case you configured an \c admin_key
* property and extended it to RTP forwarding as well, you'll need to provide
* it in the request as well or it will be rejected as unauthorized. By
* default no limitation is posed on \c rtp_forward .
*
* A successful request will result in an \c rtp_forward response, containing
* the relevant info associated to the new forwarder(s):
*
\verbatim
{
"videoroom" : "rtp_forward",
"room" : <unique numeric ID, same as request>,
"publisher_id" : <unique numeric ID, same as request>,
"rtp_stream" : {
"host" : "<host this forwarder is streaming to, same as request if not resolved>",
"audio" : <audio RTP port, same as request if configured>,
"audio_rtcp" : <audio RTCP port, same as request if configured>,
"audio_stream_id" : <unique numeric ID assigned to the audio RTP forwarder, if any>,
"video" : <video RTP port, same as request if configured>,
"video_rtcp" : <video RTCP port, same as request if configured>,
"video_stream_id" : <unique numeric ID assigned to the main video RTP forwarder, if any>,
"video_2" : <second video port, same as request if configured>,
"video_stream_id_2" : <unique numeric ID assigned to the second video RTP forwarder, if any>,
"video_3" : <third video port, same as request if configured>,
"video_stream_id_3" : <unique numeric ID assigned to the third video RTP forwarder, if any>,
"data" : <data port, same as request if configured>,
"data_stream_id" : <unique numeric ID assigned to datachannel messages forwarder, if any>
}
}
\endverbatim
*
* To stop a previously created RTP forwarder and stop it, you can use
* the \c stop_rtp_forward request, which has to be formatted as follows:
*
\verbatim
{
"request" : "stop_rtp_forward",
"room" : <unique numeric ID of the room the publisher is in>,
"publisher_id" : <unique numeric ID of the publisher to update>,
"stream_id" : <unique numeric ID of the RTP forwarder>
}
\endverbatim
*
* A successful request will result in a \c stop_rtp_forward response:
*
\verbatim
{
"videoroom" : "stop_rtp_forward",
"room" : <unique numeric ID, same as request>,
"publisher_id" : <unique numeric ID, same as request>,
"stream_id" : <unique numeric ID, same as request>
}
\endverbatim
*
* To get a list of all the forwarders in a specific room, instead, you
* can make use of the \c listforwarders request, which has to be
* formatted as follows:
*
\verbatim
{
"request" : "listforwarders",
"room" : <unique numeric ID of the room>,
"secret" : "<room secret; mandatory if configured>"
}
\endverbatim
*
* A successful request will produce a list of RTP forwarders in a
* \c forwarders response:
*
\verbatim
{
"videoroom" : "forwarders",
"room" : <unique numeric ID of the room>,
"rtp_forwarders" : [ // Array of publishers with RTP forwarders
{ // Publisher #1
"publisher_id" : <unique numeric ID of publisher #1>,
"rtp_forwarders" : [ // Array of RTP forwarders
{ // RTP forwarder #1
"audio_stream_id" : <unique numeric ID assigned to this audio RTP forwarder, if any>,
"video_stream_id" : <unique numeric ID assigned to this video RTP forwarder, if any>,
"data_stream_id" : <unique numeric ID assigned to this datachannel messages forwarder, if any>
"ip" : "<IP this forwarder is streaming to>",
"port" : <port this forwarder is streaming to>,
"rtcp_port" : <local port this forwarder is using to get RTCP feedback, if any>,
"ssrc" : <SSRC this forwarder is using, if any>,
"pt" : <payload type this forwarder is using, if any>,
"substream" : <video substream this video forwarder is relaying, if any>,
"srtp" : <true|false, whether the RTP stream is encrypted>
},
// Other forwarders for this publisher
],
},
// Other publishers
]
}
\endverbatim *
*
* To conclude, you can leave a room you previously joined as publisher
* using the \c leave request. This will also implicitly unpublish you
* if you were an active publisher in the room. The \c leave request
* looks like follows:
*
\verbatim
{
"request" : "leave"
}
\endverbatim
*
* If successful, the response will look like this:
*
\verbatim
{
"videoroom" : "event",
"leaving" : "ok"
}
\endverbatim
*
* Other participants will receive a different event depending on whether
* you were currently an active publisher ("unpublished") or simply
* lurking ("leaving"):
*
\verbatim
{
"videoroom" : "event",
"room" : <room ID>,
"leaving|unpublished" : <unique ID of the publisher who left>
}
\endverbatim
*
* \subsection vroomsub VideoRoom Subscribers
*
* In a VideoRoom, subscribers are NOT participants, but simply handles
* that will be used exclusively to receive media from a specific publisher
* in the room. Since they're not participants per se, they're basically
* streams that can be (and typically are) associated to publisher handles
* as the ones we introduced in the previous section, whether active or not.
* In fact, the typical use case is publishers being notified about new
* participants becoming active in the room, and as a result new subscriber
* sessions being created to receive their media streams; as soon as the
* publisher goes away, the subscriber handle is removed as well. As such,
* these subscriber sessions are dependent on feedback obtained by
* publishers, and can't exist on their own, unless you feed them the
* right info out of band.
*
* To specify a handle will be associated with a subscriber, you must use
* the \c join request with \c ptype set to \c subscriber and specify which
* feed to subscribe to. The exact syntax of the request is the following:
*
\verbatim
{
"request" : "join",
"ptype" : "subscriber",
"room" : <unique ID of the room to subscribe in>,
"feed" : <unique ID of the publisher to subscribe to; mandatory>,
"private_id" : <unique ID of the publisher that originated this request; optional, unless mandated by the room configuration>,
"close_pc" : <true|false, depending on whether or not the PeerConnection should be automatically closed when the publisher leaves; true by default>,
"audio" : <true|false, depending on whether or not audio should be relayed; true by default>,
"video" : <true|false, depending on whether or not video should be relayed; true by default>,
"data" : <true|false, depending on whether or not data should be relayed; true by default>,
"offer_audio" : <true|false; whether or not audio should be negotiated; true by default if the publisher has audio>,
"offer_video" : <true|false; whether or not video should be negotiated; true by default if the publisher has video>,
"offer_data" : <true|false; whether or not datachannels should be negotiated; true by default if the publisher has datachannels>,
"substream" : <substream to receive (0-2), in case simulcasting is enabled; optional>,
"temporal" : <temporal layers to receive (0-2), in case simulcasting is enabled; optional>,
"spatial_layer" : <spatial layer to receive (0-2), in case VP9-SVC is enabled; optional>,
"temporal_layer" : <temporal layers to receive (0-2), in case VP9-SVC is enabled; optional>
}
\endverbatim
*
* As you can see, it's just a matter of specifying the ID of the publisher to
* subscribe to and, if needed, your own \c private_id (if mandated by the room).
* The \c offer_audio , \c offer_video and \c offer_data are
* also particularly interesting, though, as they allow you to only subscribe
* to a subset of the mountpoint media. By default, in fact, this \c join
* request will result in the plugin preparing a new SDP offer trying to
* negotiate all the media streams made available by the publisher; in case
* the subscriber knows they don't support one of the mountpoint codecs, though
* (e.g., the video in the mountpoint is VP8, but they only support H.264),
* or are not interested in getting all the media (e.g., they're ok with
* just audio and not video, or don't have enough bandwidth for both),
* they can use those properties to shape the SDP offer to their needs.
* In case the publisher to subscribe to is simulcasting or doing VP9 SVC,
* you can choose in advance which substream you're interested in, e.g.,
* to only get the medium quality at best, instead of higher options if
* available. As we'll see later, this can be changed dynamically at any
* time using a subsequent \c configure request.
*
* As anticipated, if successful this request will generate a new JSEP SDP
* offer, which will accompany an \c attached event:
*
\verbatim
{
"videoroom" : "attached",
"room" : <room ID>,
"feed" : <publisher ID>,
"display" : "<the display name of the publisher, if any>"
}
\endverbatim
*
* At this stage, to complete the setup of the PeerConnection the subscriber is
* supposed to send a JSEP SDP answer back to the plugin. This is done
* by means of a \c start request, which in this case MUST be associated
* with a JSEP SDP answer but otherwise requires no arguments:
*
\verbatim
{
"request" : "start"
}
\endverbatim
*
* If successful this request returns a \c started event:
*
\verbatim
{
"videoroom" : "event",
"started" : "ok"
}
\endverbatim
*
* Once this is done, all that's needed is waiting for the WebRTC PeerConnection
* establishment to succeed. As soon as that happens, the Streaming plugin
* can start relaying media from the mountpoint the viewer subscribed to
* to the viewer themselves.
*
* Notice that the same exact steps we just went through (\c watch request,
* followed by JSEP offer by the plugin, followed by \c start request with
* JSEP answer by the viewer) is what you also use when renegotiations are
* needed, e.g., for the purpose of ICE restarts.
*
* As a subscriber, you can temporarily pause and resume the whole media delivery
* with a \c pause and, again, \c start request (in this case without any JSEP
* SDP answer attached). Neither expect other arguments, as the context
* is implicitly derived from the handle they're sent on:
*
\verbatim
{
"request" : "pause"
}
\endverbatim
*
\verbatim
{
"request" : "start"
}
\endverbatim
*
* Unsurprisingly, they just result in, respectively, \c paused and
* \c started events:
*
\verbatim
{
"videoroom" : "event",
"paused" : "ok"
}
\endverbatim
*
\verbatim
{
"videoroom" : "event",
"started" : "ok"
}
\endverbatim
*
* For more drill-down manipulations of a subscription, a \c configure
* request can be used instead. This request allows subscribers to dynamically
* change some properties associated to their media subscription, e.g.,
* in terms of what should and should not be sent at a specific time. A
* \c configure request must be formatted as follows:
*
\verbatim
{
"request" : "configure",
"audio" : <true|false, depending on whether audio should be relayed or not; optional>,
"video" : <true|false, depending on whether video should be relayed or not; optional>,
"data" : <true|false, depending on whether datachannel messages should be relayed or not; optional>,
"substream" : <substream to receive (0-2), in case simulcasting is enabled; optional>,
"temporal" : <temporal layers to receive (0-2), in case simulcasting is enabled; optional>,
"spatial_layer" : <spatial layer to receive (0-2), in case VP9-SVC is enabled; optional>,
"temporal_layer" : <temporal layers to receive (0-2), in case VP9-SVC is enabled; optional>
}
\endverbatim
*
* As you can see, the \c audio , \c video and \c data properties can be
* used as a media-level pause/resume functionality, whereas \c pause
* and \c start simply pause and resume all streams at the same time.
* The \c substream and \c temporal properties, instead, only make sense
* when the mountpoint is configured with video simulcasting support, and
* as such the viewer is interested in receiving a specific substream
* or temporal layer, rather than any other of the available ones.
* The \c spatial_layer and \c temporal_layer have exactly the same meaning,
* but within the context of VP9-SVC publishers, and will have no effect
* on subscriptions associated to regular publishers.
*
* Another interesting feature that subscribers can take advantage of is the
* so-called publisher "switching". Basically, when subscribed to a specific
* publisher and receiving media from them, you can at any time "switch"
* to a different publisher, and as such start receiving media from that
* other mountpoint instead. Think of it as changing channel on a TV: you
* keep on using the same PeerConnection, the plugin simply changes the
* source of the media transparently. Of course, while powerful and effective
* this request has some limitations. First of all, it switches both audio
* and video, meaning you can't just switch video and keep the audio from
* the previous publisher, for instance; besides, the two publishers
* must have the same media configuration, that is, use the same codecs,
* the same payload types, etc. In fact, since the same PeerConnection is
* used for this feature, switching to a publisher with a different
* configuration might result in media incompatible with the PeerConnection