RECORD_START|STOP event in Freeswitch ESL - freeswitch

I have setup a NodeJS application (with node_esl) and connected it with event socket layer (ESL) of a Freeswitch server deployed on Amazon AWS. See code below:
var esl = require('modesl'),
conn = new esl.Connection('SERVER_IP', PORT, 'PASSWORD', function() {
conn.api('status', function(res) {
//res is an esl.Event instance
console.log(res.getBody());
});
conn.subscribe([
'RECORD_START',
'RECORD_STOP'
], function(evt) {
console.log(evt)
});
conn.on('esl::event::RECORD_START::*', function(evt) {
console.log(evt);
});
conn.on('esl::event::RECORD_STOP::*', function(evt) {
console.log(evt);
});
});
I am recording a video conference in Freeswitch using following commands and I expect the above interface to receive the RECORD_START|STOP events. However the said events are never received.
# To start recording
conference <conf_id> recording start
# To stop recording
conference <conf_id> recording stop
Below is Freeswitch profile for the conference I am recording:
<profile name="cp">
<param name="domain" value="$${domain}"/>
<param name="rate" value="8000"/>
<param name="video-mode" value="transcode"/>
<param name="interval" value="20"/>
<param name="caller-controls" value="default"/>
<param name="energy-level" value="0"/>
<param name="conference-flags" value="wait-mod|audio-always|livearray-sync|livearray-json-status"/>
<param name="max-members" value="25"/>
<param name="sound-prefix" value="/usr/local/freeswitch/conf/sounds/"/>
<param name="enter-sound" value="tone_stream://%(200,0,500,600,700)"/>
<param name="exit-sound" value="tone_stream://%(500,0,300,200,100,50,25)"/>
</profile>
I receive majority of ESL events through this interface but not the RECORD_START|STOP. Any ideas?

I tested this out and it looks like the RECORD_START|STOP events only emit for the record application (and probably the record_session application. I did not test this), but not for conference recording.
For troubleshooting, I ran fs_cli> /event plain all from the freeswitch command line, and these events did show up when I ran conference <conf_id> recording start and conference <conf_id> recording stop.
Here is the start event:
RECV EVENT
Event-Subclass: conference::maintenance
Event-Name: CUSTOM
Core-UUID: fe0ebcc0-0c43-44ed-adb3-ce4e7ee8f48b
FreeSWITCH-Hostname: freeswitch
FreeSWITCH-Switchname: freeswitch
FreeSWITCH-IPv4: 192.168.1.114
FreeSWITCH-IPv6: ::1
Event-Date-Local: 2017-09-14 17:38:22
Event-Date-GMT: Thu, 14 Sep 2017 17:38:22 GMT
Event-Date-Timestamp: 1505410702748201
Event-Calling-File: conference_record.c
Event-Calling-Function: conference_record_thread_run
Event-Calling-Line-Number: 278
Event-Sequence: 990
Conference-Name: conference
Conference-Size: 1
Conference-Ghosts: 0
Conference-Profile-Name: cp
Conference-Unique-ID: a431361f-a59b-4319-bec1-fa76f8630197
Action: start-recording
Path:{channels=1,samplerate=8000,vw=0,vh=0,fps=0.00}/usr/local/freeswitch/log/conference_recording_1.mp3
Error: File could not be opened for recording
Here is the stop event:
RECV EVENT
Event-Subclass: conference::maintenance
Event-Name: CUSTOM
Core-UUID: fe0ebcc0-0c43-44ed-adb3-ce4e7ee8f48b
FreeSWITCH-Hostname: freeswitch
FreeSWITCH-Switchname: freeswitch
FreeSWITCH-IPv4: 192.168.1.114
FreeSWITCH-IPv6: ::1
Event-Date-Local: 2017-09-14 17:38:22
Event-Date-GMT: Thu, 14 Sep 2017 17:38:22 GMT
Event-Date-Timestamp: 1505410702748201
Event-Calling-File: conference_record.c
Event-Calling-Function: conference_record_thread_run
Event-Calling-Line-Number: 418
Event-Sequence: 991
Conference-Name: conference
Conference-Size: 1
Conference-Ghosts: 0
Conference-Profile-Name: cp
Conference-Unique-ID: a431361f-a59b-4319-bec1-fa76f8630197
Action: stop-recording
Path: {channels=1,samplerate=8000,vw=0,vh=0,fps=0.00}/usr/local/freeswitch/log/conference_recording_1.mp3
Other-Recordings: true
Samples-Out: 0
Samplerate: 8000
Milliseconds-Elapsed: 0
For your node app, you could try something like this to get what you need:
var esl = require('modesl'),
conn = new esl.Connection('127.0.0.1', 8021, 'ClueCon', function() {
conn.api('status', function(res) {
//res is an esl.Event instance
console.log(res.getBody());
});
conn.subscribe('CUSTOM conference::maintenance', function() {
conn.on('esl::event::CUSTOM::**', function(evt) {
console.log(evt);
// now do something
});
});
});

Related

How to obtain a client secret in a teams toolkit project?

I'm working on a tab app where I intend using an on-behalf-of flow to obtain access token from azure active directory, so as to request data from Microsoft graph endpoints, and implementing this requires a client secret.
Is there a way I can get the client secret in a teams toolkit project just like I can get an application ID?
(Update) Details of what I'm trying to do
I'm working on an app where I would be calling Microsoft graph endpoints (protected by azure ad) to get data. The challenge I'm facing currently is how to handle authentication in a Teams tab app project created using Microsoft Teams Toolkit, so as to obtain an access token to request data from the graph endpoints or create an authenticated graph client.
What I have tried:
I have tried the code below, using the teamsfx.login() function within the react component where I'm calling a protected graph endpoint. But whenever I click the button to initiate a graph call, there is always a pop-up flash.
export const GraphEmail: React.FC = () => {
const [messages, setMessages] = useState<any[]>([]);
const handleGetMyMessagesOnClick = async (event: any): Promise<void> => {
await getMessages();
};
const getMessages = async (promptConsent: boolean = false): Promise<void> => {
const teamsfx = new TeamsFx();
await teamsfx.login(["User.Read", "Mail.Read"]);
const graphClient = createMicrosoftGraphClient(teamsfx, ["User.Read", "Mail.Read"]);
await graphClient
.api("/me/messages")
.select(["receivedDateTime", "subject"])
.top(15)
.get(async (error: any, rawMessages: any, rawResponse?: any) => {
if (!error) {
setMessages(rawMessages.value);
Promise.resolve();
} else {
console.error("graph error", error);
}
});
};
return (
<Flex column gap="gap.small">
<Header>Recent messages in current user&apos;s mailbox</Header>
<Button primary
content="Get My Messages"
onClick={handleGetMyMessagesOnClick}></Button>
<List selectable>
{
messages.map((message, i) => (
<List.Item key={i} media={<EmailIcon></EmailIcon>}
header={message.receivedDateTime}
content={message.subject} index={i}>
</List.Item>
))
}
</List>
</Flex>
);
}
In order to remove the consistent flash after the first popup for the actual login, since the user is already logged-in during the first button click, I made the changes below (idea gotten from the useGraph() component code on GitHub). But then I got an "uncaught (in promise) undefined" error when the button is clicked. The console logs are displayed below too.
export const NewGraphEmail: React.FC = () => {
const [needConsent, setNeedConsent] = useState(false);
const [messages, setMessages] = useState<any[]>([]);
const handleGetMyMessagesOnClick = async (event: any): Promise<void> => {
await getMessages();
};
const getMessages = async (promptConsent: boolean = false): Promise<void> => {
const teamsfx = new TeamsFx();
const scope = ["User.Read", "Mail.Read"];
if (needConsent) {
try {
await teamsfx.login(scope);
setNeedConsent(false);
// Important: tokens are stored in sessionStorage, read more here: https://aka.ms/teamsfx-session-storage-notice
} catch (err: unknown) {
if (err instanceof ErrorWithCode && err.message?.includes("CancelledByUser")) {
const helpLink = "https://aka.ms/teamsfx-auth-code-flow";
err.message +=
'\nIf you see "AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application" ' +
"in the popup window, you may be using unmatched version for TeamsFx SDK (version >= 0.5.0) and Teams Toolkit (version < 3.3.0) or " +
`cli (version < 0.11.0). Please refer to the help link for how to fix the issue: ${helpLink}`;
}
throw err;
}
}
const graphClient = createMicrosoftGraphClient(teamsfx, scope);
await graphClient
.api("/me/messages")
.select(["receivedDateTime", "subject"])
.top(15)
.get(async (error: any, rawMessages: any, rawResponse?: any) => {
if (!error) {
setMessages(rawMessages.value);
Promise.resolve();
} else if (error instanceof GraphError && error.code?.includes("UiRequiredError")) {
// Silently fail for user didn't consent error
setNeedConsent(true);
// getMessages();
} else {
console.log("graph error", error);
}
});
};
return (
<Flex column gap="gap.small">
<Header>Recent messages in current user&apos;s mailbox</Header>
<Button primary
content="Get My Messages"
onClick={handleGetMyMessagesOnClick}></Button>
<List selectable>
{
messages.map((message, i) => (
<List.Item key={i} media={<EmailIcon></EmailIcon>}
header={message.receivedDateTime}
content={message.subject} index={i}>
</List.Item>
))
}
</List>
</Flex>
);
}
The logs in the browser console
[Tue, 09 Aug 2022 10:22:00 GMT] : #microsoft/teamsfx : Info - Create
Microsoft Graph Client useTeamsFx.js:34
[Tue, 09 Aug 2022 10:22:00 GMT] : #microsoft/teamsfx : Info - Create
Microsoft Graph Authentication Provider with scopes: 'User.Read Mail.Read'
useTeamsFx.js:34
[Tue, 09 Aug 2022 10:22:00 GMT] : #microsoft/teamsfx : Info - Get Graph
Access token with scopes: 'User.Read Mail.Read'
useTeamsFx.js:34
[Tue, 09 Aug 2022 10:22:00 GMT] : #microsoft/teamsfx : Info - Create teams
user credential useTeamsFx.js:34
[Tue, 09 Aug 2022 10:22:00 GMT] : #microsoft/teamsfx : Verbose - Validate
authentication configuration
useTeamsFx.js:34
[Tue, 09 Aug 2022 10:22:00 GMT] : #microsoft/teamsfx : Info - Get access
token with scopes: User.Read Mail.Read
useTeamsFx.js:34
[Tue, 09 Aug 2022 10:22:00 GMT] : #microsoft/teamsfx : Verbose - Get SSO
token from memory cache
useTeamsFx.js:34
[Tue, 09 Aug 2022 10:22:00 GMT] : #microsoft/teamsfx : Verbose - Failed to
call acquireTokenSilent. Reason: no_account_error: No account object
provided to acquireTokenSilent and no active account has been set. Please
call setActiveAccount or provide an account on the request..
authorize:74 BSSO Telemetry:
{"result":"Error","error":"NoExtension","type":"ChromeSsoTelemetry","data":
{},"traces":["BrowserSSO Initialized","Creating ChromeBrowserCore
provider","Sending message for method CreateProviderAsync","Received message
for method CreateProviderAsync","Error: ChromeBrowserCore error NoExtension:
Extension is not installed."]}
DevTools failed to load source map: Could not load content for
https://login.microsoftonline.com/5d2e66da-54ba-4897-82ee-
60eeb8ce5994/oauth2/v2.0/4616d84a89b332161726.map: HTTP error: status code
404, net::ERR_HTTP_RESPONSE_CODE_FAILURE
useTeamsFx.js:34
[Tue, 09 Aug 2022 10:22:02 GMT] : #microsoft/teamsfx : Verbose - Failed to
call ssoSilent. Reason: login_required: AADSTS50058: A silent sign-in
request was sent but no user is signed in.
Trace ID: 5043daaa-b142-4083-9ad9-a798c2303b00
Correlation ID: ce16ec27-0261-423e-96f6-810344f76647
Timestamp: 2022-08-09 10:22:03Z.
useTeamsFx.js:34
[Tue, 09 Aug 2022 10:22:02 GMT] : #microsoft/teamsfx : Error - Failed to get
access token cache silently, please login first: you need login first before
get access token.
TestGraph.tsx:16
Uncaught (in promise) undefined
The uncaught error points to the end of the "handleGetMyMessagesOnClick" function above.
The other options:
The useGraph() hook: I would have loved to use the hook directly, but it seem to be suited for cases when using microsoft graph toolkit components, which won't serve my purpose during the project.
The on-behalf-of flow: I believe this would have solved the problem, following the steps in this video from the Microsoft 365 Developer channel, but the solution requires having an azure ad app client secret, which I don't know how to get in a microsoft teams toolkit project, since microsoft teams toolkit handles azure ad app registration.
A Client secret is a password to optain an access token though an API.
You need to implement an API than kan exchange an Teams SSO token, for a MS Graph API access token using a client secret (on-behalf-of). This client secret must never be exposed to the user/client, and should be secret; hence the name.
See this for a detailed explaination.
What you're wanting in this case is an "on behalf of" token from Graph, which lets you make calls to graph from your app as if it was the user ("on behalf of" the user) and it seems reasonable enough at first to do this in your client-side code. However, it turns out this isn't actually secure because it means the user's token is flying around almost in the open. As a result, it's better to create your own backend API (e.g. in an Azure Function) and make the "on behalf of" ("OBO") call from within there. Teams Toolkit actually creates some structure to help with this backend API, I think.
I'm not sure how well it covers Teams Toolkit (it's a while since I last watched it), but this video is an excellent overview: https://www.youtube.com/watch?v=kruUnaZgQaY . See here also for info: https://learn.microsoft.com/en-us/microsoftteams/platform/toolkit/visual-studio-code-tab-sso

Cannot received events in hyperledger composer 0.19.3 client

I am using hyperledger composer 0.19.3 with hyperledger fabric 1.1. I have a composer client app and I am trying to listen for events from a transaction that emitted the event. I can see the event in the historian within the composer rest server. However the debug trace log shows the following over and over again "could not find any connected event hubs out of 1 defined hubs to listen on for chaincode events...". The code is as follows:
This client app is modeled off the sample digitalProperty land title example.
listen() {
LOG.info('Awaiting events');
this.bizNetworkConnection.on('event', (event) => {
// event: { "$class": "org.namespace.BasicEvent", "eventId": "0000-0000-0000-000000#0" }
console.log(event);
});
}

Setting up ejabberd via websockets

I have an ejabberd server up and running.
I can test it via web clients and it works fine using BOSH connections.
I would like to connect to it via web sockets now, and I am not sure what I am missing for it to work, I just know it doesn't.
Here is an extract from my ejabberd.yml
hosts:
- "localhost"
- "somedomain.com"
- "im.somedomain.com"
listen :
port: 5280
ip: "::"
module: ejabberd_http
request_handlers:
"/websocket": ejabberd_http_ws
"/pub/archive": mod_http_fileserver
web_admin: true
http_bind: true
## register: true
## captcha: true
tls: true
certfile: "/etc/ejabberd/ejabberd.pem"
Now I tried to open a web socket via javascript as follows :
var ws = new WebSocket("ws://somedomain:5280/websocket/");
I get ERR_CONNECTION_TIMED_OUT in return. I have nothing within ejabberd's logs when I try to open a weksocket. I do have logs of the BOSH connections.
I am not sure if I am testing appropriately, nor if my server is setup correctly.
Any suggestion is most welcome.
Connection timeout error will throw by the server when the client does not send pong response to the server make sure you are sending the pong response.If you are using Strophe.js kindly check Handlers http://strophe.im/strophejs/doc/1.2.14/files/strophe-js.html#Strophe.Connection.addHandler
connection = new WebSocket("ws://somedomain:5280/websocket/");
//Adding ping handler using strophe connection
connection.addHandler(pingHandler, "urn:xmpp:ping", "iq", "get");
//Ping Handler Call back function
function pingHandler(ping) {
var pingId = ping.getAttribute("id");
var from = ping.getAttribute("from");
var to = ping.getAttribute("to");
var pong = strophe.$iq({
type: "result",
"to": from,
id: pingId,
"from": to
});
connection.send(pong);
return true;
}
Also, consider you are adding this configuration to your ejabberd.yml
websocket_ping_interval: 50
websocket_timeout: 60

Connecting freeswitch remotely using node esl fails

Im trying to connect remotely to FreeSwitch service using ESL.
Connecting machine and FS Service both are in my local VM's, 2 different VM's
But i get below error
[WARNING] mod_event_socket.c:2639 IP 10.95.38.254 Rejected by acl "loopback.auto"
/autoload_configs/event_socket.conf.xml
<configuration name="event_socket.conf" description="Socket Client">
<settings>
<param name="listen-ip" value="0.0.0.0"/>
<param name="listen-port" value="8021"/>
<param name="password" value="ClueCon"/>
</settings>
</configuration>
Script:
var conn = new esl.Connection('10.191.73.254', 8021, 'ClueCon', function() {
conn.api('status', function(res) {
console.log(' >> Connected >> ');
console.log(res.getBody());
});
});
I added below lines into acl.config.xml and its working fine
/auto_configs/acl.config.xml
<list name="loopback.auto" default="allow">
<node type="allow" cidr="10.95.38.0/24"/>
</list>
you need to use apply-inbound-acl explicitly in your event_socket.conf.xml. If none is applied, the default loopback ACL is used for ESL.

Why does a websocket in PebbleKit JS cause iOS app to crash?

I am attempting to log Pebble accelerometer data to my computer. I was hoping to use PebbleKit JS to communicate with the watch itself, and then use websockets to send that data to my computer, but currently the websocket only sends one message and then the iOS app crashes.
Here is the content of pebble-js-app.js:
var ws = new WebSocket('ws://192.168.1.134:8888');
// Called when JS is ready
Pebble.addEventListener("ready",
function(e) {
console.log("js initialized");
}
);
// Called when incoming message from the Pebble is received
Pebble.addEventListener("appmessage",
function(e) {
console.log(ws.readyState);
if (ws.readyState === 1) {
ws.send('this gets sent');
ws.send(e.payload.message);
}
console.log("acc data: " + e.payload.message);
}
);
And here is the log that I get when I run the app:
[INFO ] Enabling application logging...
[INFO ] Displaying logs ... Ctrl-C to interrupt.
[INFO ] JS: starting app: 4C74DC80-A54E-4D0B-9BAB-FD355D364334 accelero
[INFO ] app is ready: 1
[INFO ] JS: accelerometer: js initialized
[INFO ] JS: accelerometer: 0
[INFO ] JS: accelerometer: acc data: 3131
[INFO ] JS: accelerometer: 1
[ERROR ] Lost connection to Pebble
The websocket server running on my computer logs the first message sent from the javascript. Only one message is sent, even when the order is changed (e.g. it prints either this gets sent or a single actual reading from the accelerometer). Curiously, the built-in logging (console.log) from javascript started only printing 3131 for the received data, even when the websocket sends some valid data. Can you see any errors in the code or do you have any other suggestions?

Resources