Skip to content
Snippets Groups Projects
Commit 9f237d13 authored by Simon Döring's avatar Simon Döring
Browse files

Add feature to change janus room pin

parent 77b3405d
Branches
No related tags found
No related merge requests found
...@@ -114,10 +114,16 @@ For the syntax of the commands the following convention is used in this document ...@@ -114,10 +114,16 @@ For the syntax of the commands the following convention is used in this document
* `<a | b>` is a parameter that is required and has to hold either the value `a` or `b`. * `<a | b>` is a parameter that is required and has to hold either the value `a` or `b`.
* `[param]` is a parameter that is optional * `[param]` is a parameter that is optional.
This is the list of the available commands: This is the list of the available commands:
### Room Control Commands
| Command | Description
| --------------------------------- | -----------
| `edit_pin` | Changes the pin of the Janus room. This pin is required to join the room as a viewer or sender. Note that this does not automatically kick the current participants of the Janus room. The noVNC pin also needs to be changed accordingly as it is expected to equal the Janus room pin. <br/><br/> **Usage**: `edit_pin <pin>`
### Slot Control Commands ### Slot Control Commands
| Command | Description | Command | Description
......
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
emitControllerBitrateLimit emitControllerBitrateLimit
} from '../../socket-io/handlers/sender-handlers'; } from '../../socket-io/handlers/sender-handlers';
import { setBitrate } from '../../janus/handlers'; import { setBitrate } from '../../janus/handlers';
import { room } from '../../janus/janus-room';
import { config } from '../../config/config'; import { config } from '../../config/config';
const visibilityCommands = ['hide', 'show']; const visibilityCommands = ['hide', 'show'];
...@@ -16,7 +17,7 @@ const geometryCommands = [ ...@@ -16,7 +17,7 @@ const geometryCommands = [
'set_geometry_relative_to_window', 'set_geometry_relative_to_window',
'set_geometry_relative_to_canvas' 'set_geometry_relative_to_canvas'
]; ];
const internalCommands = [ const internalSlotCommands = [
'activate_slot', 'activate_slot',
'deactivate_slot', 'deactivate_slot',
'refresh_token', 'refresh_token',
...@@ -24,6 +25,7 @@ const internalCommands = [ ...@@ -24,6 +25,7 @@ const internalCommands = [
'remove_annotation', 'remove_annotation',
'set_bitrate_limit' 'set_bitrate_limit'
]; ];
const internalRoomCommands = ['edit_pin'];
const setAnnotation = (slot: number, annotation: string) => { const setAnnotation = (slot: number, annotation: string) => {
console.log(`Setting annotation of slot ${slot} to ${annotation}`); console.log(`Setting annotation of slot ${slot} to ${annotation}`);
...@@ -33,7 +35,7 @@ const setAnnotation = (slot: number, annotation: string) => { ...@@ -33,7 +35,7 @@ const setAnnotation = (slot: number, annotation: string) => {
} }
}; };
const handleInternalCommand = ( const handleInternalSlotCommand = (
command: string, command: string,
slot: number, slot: number,
params: string[] params: string[]
...@@ -155,7 +157,28 @@ const handleInternalCommand = ( ...@@ -155,7 +157,28 @@ const handleInternalCommand = (
break; break;
default: default:
console.log( console.log(
'Error: handleInternalCommand got unknown command ' + command 'Error: handleInternalSlotCommand got unknown command ' +
command
);
break;
}
};
const handleInternalRoomCommand = (command: string, params: string[]) => {
switch (command) {
case 'edit_pin':
const newPin = params[0];
if (newPin === null) {
console.log(
'Tried to edit janus room pin without providing one'
);
return;
}
room.editPin(newPin);
break;
default:
console.log(
`Error: handleInternalRoomCommand got unknown command ${command}`
); );
break; break;
} }
...@@ -173,6 +196,12 @@ export const handleCommand = (line: string) => { ...@@ -173,6 +196,12 @@ export const handleCommand = (line: string) => {
return; return;
} }
console.log('command:', command);
console.log('params:', params);
if (internalRoomCommands.includes(command)) {
handleInternalRoomCommand(command, params);
} else {
const slotStr = params.shift(); const slotStr = params.shift();
if (slotStr == null) { if (slotStr == null) {
console.log('Error: Got no slot to apply the command on'); console.log('Error: Got no slot to apply the command on');
...@@ -193,10 +222,6 @@ export const handleCommand = (line: string) => { ...@@ -193,10 +222,6 @@ export const handleCommand = (line: string) => {
return; return;
} }
console.log('command:', command);
console.log('slot:', slot);
console.log('params:', params);
const currentCameraState = cameraSlotState[slot]; const currentCameraState = cameraSlotState[slot];
if (visibilityCommands.includes(command)) { if (visibilityCommands.includes(command)) {
...@@ -211,8 +236,8 @@ export const handleCommand = (line: string) => { ...@@ -211,8 +236,8 @@ export const handleCommand = (line: string) => {
params params
}; };
emitCommand = true; emitCommand = true;
} else if (internalCommands.includes(command)) { } else if (internalSlotCommands.includes(command)) {
handleInternalCommand(command, slot, params); handleInternalSlotCommand(command, slot, params);
} else { } else {
console.log('Command "' + command + '" is not a valid command'); console.log('Command "' + command + '" is not a valid command');
return; return;
...@@ -227,4 +252,5 @@ export const handleCommand = (line: string) => { ...@@ -227,4 +252,5 @@ export const handleCommand = (line: string) => {
params params
}); });
} }
}
}; };
...@@ -113,3 +113,21 @@ export const destroyRoom = ( ...@@ -113,3 +113,21 @@ export const destroyRoom = (
} }
}); });
}; };
export const editRoomPin = (
sessionId: number,
videoroomId: number,
room: number,
secret: string,
newPin: string
) => {
return postRequest(`/${sessionId}/${videoroomId}`, {
janus: 'message',
body: {
request: 'edit',
room,
secret,
new_pin: newPin
}
});
};
...@@ -149,6 +149,35 @@ class JanusRoom { ...@@ -149,6 +149,35 @@ class JanusRoom {
} }
} }
async editPin(newPin: string) {
console.log(`Changing janus room pin to ${newPin}`);
if (!this._sessionAlive) {
console.log("Error: Janus session timed out - can't send request");
return;
}
const { data } = await janusAPI.editRoomPin(
this.sessionId,
this.videoroomId,
config.janusRoom,
config.janusRoomSecret,
newPin
);
if (
data?.janus === 'success' &&
data.plugindata?.data?.videoroom === 'edited'
) {
console.log('Changed janus room pin');
} else {
console.log(
`Error: Could not change janus room pin. Janus response: ${JSON.stringify(
data,
null,
2
)}`
);
}
}
async cleaup() { async cleaup() {
console.log(`Cleaning up janus room ${config.janusRoom}`); console.log(`Cleaning up janus room ${config.janusRoom}`);
if (this._sessionAlive) { if (this._sessionAlive) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment