|
const xapi = require('xapi'); |
|
const MAINCAMERAID = '1'; |
|
const PRESENTATIONCAMERAID = '2'; |
|
|
|
//var farendCameraToControl = 'MAIN'; |
|
var farendCameraToControl = 'PRESENTATION'; |
|
|
|
var currentCallId = null; |
|
var farendpresentationactive = 0; |
|
|
|
//Send control commands via SIP to remtoe end |
|
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 sendCameraStopControl(selectedCameraId){ |
|
xapi.command('Camera Ramp', { CameraId: selectedCameraId, Zoom: 'Stop', Pan: 'Stop', Tilt:'Stop', 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; |
|
}); |
|
|
|
|
|
//Recieve input from touch 10 UI widgets |
|
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'); |
|
} |
|
} |
|
}); |
|
|
|
|
|
//Recieved messages to control local camera |
|
xapi.event.on('FarEndMessage Receive', (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': |
|
sendCameraStopControl(MAINCAMERAID); |
|
break; |
|
case 'CAMERA:MAIN;DIRECTION:UpPressed': |
|
sendCameraTiltControl('Up', MAINCAMERAID); |
|
break; |
|
case 'CAMERA:MAIN;DIRECTION:DownPressed': |
|
sendCameraTiltControl('Down', MAINCAMERAID); |
|
break; |
|
case 'CAMERA:MAIN;DIRECTION:LeftPressed': |
|
sendCameraPanControl('Left', MAINCAMERAID); |
|
break; |
|
case 'CAMERA:MAIN;DIRECTION:RightPressed': |
|
sendCameraPanControl('Right', MAINCAMERAID); |
|
break; |
|
case 'CAMERA:MAIN;DIRECTION:ZoomIn': |
|
sendCameraZoomControl('In', MAINCAMERAID); |
|
break; |
|
case 'CAMERA:MAIN;DIRECTION:ZoomOut': |
|
sendCameraZoomControl('Out', MAINCAMERAID); |
|
break; |
|
} |
|
} |
|
}); |
|
|
|
xapi.config.set('Conference FarendMessage Mode', 'On').catch((error) => { |
|
console.error(error); |
|
}); |