@@ -110,6 +110,7 @@ const logger = new Logger("SESSION");
110110 *
111111 * @fires Session#stateChange - Emitted when session state changes
112112 * @fires Session#close - Emitted when session is closed
113+ * @fires Session#producer - Emitted when a new producer is created
113114 */
114115export class Session extends EventEmitter {
115116 /** Communication bus for WebSocket messaging */
@@ -138,9 +139,9 @@ export class Session extends EventEmitter {
138139 camera : null ,
139140 screen : null
140141 } ;
141- public permissions : SessionPermissions = {
142+ public readonly permissions : SessionPermissions = Object . seal ( {
142143 recording : false
143- } ;
144+ } ) ;
144145 /** Parent channel containing this session */
145146 private readonly _channel : Channel ;
146147 /** Recovery timeouts for failed consumers */
@@ -184,9 +185,26 @@ export class Session extends EventEmitter {
184185
185186 set state ( state : SESSION_STATE ) {
186187 this . _state = state ;
188+ /**
189+ * @event Session#stateChange
190+ * @type {{ state: SESSION_STATE } }
191+ */
187192 this . emit ( "stateChange" , state ) ;
188193 }
189194
195+ updatePermissions ( permissions : SessionPermissions | undefined ) : void {
196+ if ( ! permissions ) {
197+ return ;
198+ }
199+ for ( const key of Object . keys ( this . permissions ) as ( keyof SessionPermissions ) [ ] ) {
200+ const newVal = permissions [ key ] ;
201+ if ( newVal === undefined ) {
202+ continue ;
203+ }
204+ this . permissions [ key ] = Boolean ( permissions [ key ] ) ;
205+ }
206+ }
207+
190208 async getProducerBitRates ( ) : Promise < ProducerBitRates > {
191209 const bitRates : ProducerBitRates = { } ;
192210 const proms : Promise < void > [ ] = [ ] ;
@@ -643,8 +661,25 @@ export class Session extends EventEmitter {
643661 logger . debug ( `[${ this . name } ] producing ${ type } : ${ codec ?. mimeType } ` ) ;
644662 this . _updateRemoteConsumers ( ) ;
645663 this . _broadcastInfo ( ) ;
664+ /**
665+ * @event Session#producer
666+ * @type {{ type: StreamType, producer: Producer } }
667+ */
668+ this . emit ( "producer" , { type, producer } ) ;
646669 return { id : producer . id } ;
647670 }
671+ case CLIENT_REQUEST . START_RECORDING : {
672+ if ( this . permissions . recording && this . _channel . recorder ) {
673+ return this . _channel . recorder . start ( ) ;
674+ }
675+ return ;
676+ }
677+ case CLIENT_REQUEST . STOP_RECORDING : {
678+ if ( this . permissions . recording && this . _channel . recorder ) {
679+ return this . _channel . recorder . stop ( ) ;
680+ }
681+ return ;
682+ }
648683 default :
649684 logger . warn ( `[${ this . name } ] Unknown request type: ${ name } ` ) ;
650685 throw new Error ( `Unknown request type: ${ name } ` ) ;
0 commit comments