Skip to content

Instantly share code, notes, and snippets.

@voipnorm
Last active May 28, 2019 21:20
Show Gist options
  • Save voipnorm/4ae351a78ab0f593a7ffaaff7fb36dac to your computer and use it in GitHub Desktop.
Save voipnorm/4ae351a78ab0f593a7ffaaff7fb36dac to your computer and use it in GitHub Desktop.
const xapi = require('xapi');
const MAINCAMERAID = '1';
const PRESENTATIONCAMERAID = '2';
//var farendCameraToControl = 'MAIN';
var farendCameraToControl = 'PRESENTATION';
var currentCallId = null;
var farendpresentationactive = 0;
var lastDirection = null;
function sendFECC(key){
if(currentCallId){
xapi.command('Call FarEndMessage Send', { Text: 'CAMERA:' + farendCameraToControl + ';DIRECTION:' + key, CallId: currentCallId, Type: 'FECC'}).catch((error) => { console.error(JSON.stringify(error)); });
xapi.command('UserInterface Message TextLine Display', {'Text': "Controlling far-end camera", 'x':"5000", 'y':"1000", 'Duration': "5"});
}
else{
console.log('No CallId. SendFECC request ignored');
}
}
function sendFECC_StartStopPresentation(){
if(farendpresentationactive === 0){
xapi.command('Call FarEndMessage Send', { Text: 'PRESENTATIONSTART', CallId: currentCallId, Type: 'FECC'}).catch((error) => { console.error(JSON.stringify(error)); });
farendpresentationactive = 1;
}
else{
xapi.command('Call FarEndMessage Send', { Text: 'PRESENTATIONSTOP', CallId: currentCallId, Type: 'FECC'}).catch((error) => { console.error(JSON.stringify(error)); });
farendpresentationactive = 0;
}
}
function sendCameraTiltControl(direction, selectedCameraId){
xapi.command('Camera Ramp', { CameraId: selectedCameraId, Tilt: direction})
.catch((error) => { console.error(JSON.stringify(error)); });
}
function sendCameraPanControl(direction, selectedCameraId){
xapi.command('Camera Ramp', { CameraId: selectedCameraId, Pan: direction})
.catch((error) => { console.error(JSON.stringify(error)); });
}
function sendCameraZoomControl(direction, selectedCameraId){
xapi.command('Camera Ramp', { CameraId: selectedCameraId, Zoom: direction})
.catch((error) => { console.error(JSON.stringify(error)); });
}
function sendCameraFocusControl(direction, selectedCameraId){
xapi.command('Camera Ramp', { CameraId: selectedCameraId, Focus: direction})
.catch((error) => { console.error(JSON.stringify(error)); });
}
function sendCameraZoomStopControl(selectedCameraId){
xapi.command('Camera Ramp', { CameraId: selectedCameraId, Zoom: 'Stop'})
.catch((error) => { console.error(JSON.stringify(error)); });
}
function sendCameraTiltStopControl(selectedCameraId){
xapi.command('Camera Ramp', { CameraId: selectedCameraId,Tilt: 'Stop'})
.catch((error) => { console.error(JSON.stringify(error)); });
}
function sendCameraPanStopControl(selectedCameraId){
xapi.command('Camera Ramp', { CameraId: selectedCameraId, Pan: 'Stop'})
.catch((error) => { console.error(JSON.stringify(error)); });
}
function sendCameraFocusStopControl(selectedCameraId){
xapi.command('Camera Ramp', { CameraId: selectedCameraId, Focus: 'Stop'})
.catch((error) => { console.error(JSON.stringify(error)); });
}
xapi.status.on('Call', (callinfo) => {
// console.log('New CallId: ' + JSON.stringify(callinfo));
if(callinfo.Status == "Connected"){
currentCallId = callinfo.id;
console.log('New CallId ' + currentCallId);
}
else if(callinfo.ghost == "True"){
currentCallId = null;
console.log('CallId nullified');
}
farendpresentationactive = 0;
});
xapi.event.on('UserInterface Extensions Widget Action', (event) => {
if(event.WidgetId == 'fabriccam_ptzf'){
if(event.Type == 'pressed'){
switch(event.Value){
case 'right':
sendFECC('RightPressed');
break;
case 'left':
sendFECC('LeftPressed');
break;
case 'up':
sendFECC('UpPressed');
break;
case 'down':
sendFECC('DownPressed');
break;
case 'center':
sendFECC_StartStopPresentation();
break;
default:
console.log(`Unhandled Navigation`);
}
}
if(event.Type == 'released'){
sendFECC('STOP');
}
}
});
xapi.event.on('UserInterface InputDevice Key Action', (event) => {
if(event.Type == 'Pressed'){
if(event.Key == 'KEY_LEFT'){
sendFECC('LeftPressed');
}
else if(event.Key == 'KEY_RIGHT'){
sendFECC('RightPressed');
}
else if(event.Key == 'KEY_UP'){
sendFECC('UpPressed');
}
else if(event.Key == 'KEY_DOWN'){
sendFECC('DownPressed');
}
else if(event.Key == 'KEY_REWIND'){
sendFECC('ZoomOut');
}
else if(event.Key == 'KEY_FASTFORWARD'){
sendFECC('ZoomIn');
}
else if(event.Key == 'KEY_ENTER'){
sendFECC_StartStopPresentation();
}
}
else if(event.Type == 'Released'){
switch(event.Key){
case 'KEY_LEFT':
case 'KEY_RIGHT':
case 'KEY_UP':
case 'KEY_DOWN':
case 'KEY_REWIND':
case 'KEY_FASTFORWARD':
sendFECC('STOP');
break;
}
}
});
xapi.event.on('UserInterface Extensions Widget Action', (event) => {
if(event.WidgetId == 'fecc_control'){
if(event.Type == 'pressed'){
switch(event.Value){
case 'right':
sendFECC('RightPressed');
break;
case 'left':
sendFECC('LeftPressed');
break;
case 'up':
sendFECC('UpPressed');
break;
case 'down':
sendFECC('DownPressed');
break;
}
}
else if(event.Type == 'released'){
sendFECC('STOP');
}
}
else if(event.WidgetId == 'fecc_zoom'){
if(event.Type == 'pressed'){
switch(event.Value){
case 'increment':
sendFECC('ZoomIn');
break;
case 'decrement':
sendFECC('ZoomOut');
break;
}
}
else if(event.Type == 'released'){
sendFECC('STOP');
}
}
});
xapi.event.on('FarEndMessage Receive', (event) => {
console.log(event);
if(event.Type == 'FECC'){
switch(event.Msg){
case 'CAMERA:PRESENTATION;DIRECTION:STOP':
sendCameraStopControl(PRESENTATIONCAMERAID);
break;
case 'CAMERA:PRESENTATION;DIRECTION:UpPressed':
sendCameraTiltControl('Up', PRESENTATIONCAMERAID);
break;
case 'CAMERA:PRESENTATION;DIRECTION:DownPressed':
sendCameraTiltControl('Down', PRESENTATIONCAMERAID);
break;
case 'CAMERA:PRESENTATION;DIRECTION:LeftPressed':
sendCameraPanControl('Left', PRESENTATIONCAMERAID);
break;
case 'CAMERA:PRESENTATION;DIRECTION:RightPressed':
sendCameraPanControl('Right', PRESENTATIONCAMERAID);
break;
case 'CAMERA:PRESENTATION;DIRECTION:ZoomIn':
sendCameraZoomControl('In', PRESENTATIONCAMERAID);
break;
case 'CAMERA:PRESENTATION;DIRECTION:ZoomOut':
sendCameraZoomControl('Out', PRESENTATIONCAMERAID);
break;
case 'PRESENTATIONSTART':
xapi.command('Presentation Start', {'ConnectorId': PRESENTATIONCAMERAID});
break;
case 'PRESENTATIONSTOP':
xapi.command('Presentation Stop');
break;
case 'CAMERA:MAIN;DIRECTION:STOP':
console.log(lastDirection)
switch(lastDirection){
case 'Zoom':
sendCameraZoomStopControl(MAINCAMERAID);
break;
case 'Pan':
sendCameraPanStopControl(MAINCAMERAID);
break;
case 'Tilt':
sendCameraTiltStopControl(MAINCAMERAID);
break;
case 'Focus':
sendCameraFocusStopControl(MAINCAMERAID);
break;
}
break;
case 'CAMERA:MAIN;DIRECTION:UpPressed':
sendCameraTiltControl('Up', MAINCAMERAID);
lastDirection = 'Tilt';
break;
case 'CAMERA:MAIN;DIRECTION:DownPressed':
sendCameraTiltControl('Down', MAINCAMERAID);
lastDirection = 'Tilt';
break;
case 'CAMERA:MAIN;DIRECTION:LeftPressed':
sendCameraPanControl('Left', MAINCAMERAID);
lastDirection = 'Pan';
break;
case 'CAMERA:MAIN;DIRECTION:RightPressed':
sendCameraPanControl('Right', MAINCAMERAID);
lastDirection = 'Pan';
break;
case 'CAMERA:MAIN;DIRECTION:ZoomIn':
sendCameraZoomControl('In', MAINCAMERAID);
lastDirection = 'Zoom';
break;
case 'CAMERA:MAIN;DIRECTION:ZoomOut':
sendCameraZoomControl('Out', MAINCAMERAID);
lastDirection = 'Zoom';
break;
}
}
});
xapi.config.set('Conference FarendMessage Mode', 'On').catch((error) => {
console.error(error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment