@@ -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 > [ ] = [ ] ;
@@ -651,8 +669,25 @@ export class Session extends EventEmitter {
651669 logger . debug ( `[${ this . name } ] producing ${ type } : ${ codec ?. mimeType } ` ) ;
652670 this . _updateRemoteConsumers ( ) ;
653671 this . _broadcastInfo ( ) ;
672+ /**
673+ * @event Session#producer
674+ * @type {{ type: StreamType, producer: Producer } }
675+ */
676+ this . emit ( "producer" , { type, producer } ) ;
654677 return { id : producer . id } ;
655678 }
679+ case CLIENT_REQUEST . START_RECORDING : {
680+ if ( this . permissions . recording && this . _channel . recorder ) {
681+ return this . _channel . recorder . start ( ) ;
682+ }
683+ return ;
684+ }
685+ case CLIENT_REQUEST . STOP_RECORDING : {
686+ if ( this . permissions . recording && this . _channel . recorder ) {
687+ return this . _channel . recorder . stop ( ) ;
688+ }
689+ return ;
690+ }
656691 default :
657692 logger . warn ( `[${ this . name } ] Unknown request type: ${ name } ` ) ;
658693 throw new Error ( `Unknown request type: ${ name } ` ) ;
0 commit comments