How can I activate or deactivate my own microphone in a conference in circuit? - circuit

How can I activate or deactivate my own microphone in a conference? we used this:
client.muteDevice(call.callId, null, {mic: true, speaker: true})
but give error

The API mute should work to mute your default mic. muteDevice is to mute another of your devices, e.g. if you are logged on with your Circuit webclient on another PC and that client is on the active call.
Example:
client.mute(call.callId).then(() => {
console.log('Unmuted');
}).catch(err => {
console.error('Failed to mute. ', err);
});
Complete example with a call is shown at https://output.jsbin.com/posoko

Related

How can I send a message from bot framework sdk after a period of inactivity? In nodejs

I am using the nodejs SDK for Bot Framework to develop a chatbot. I want to send a message to the user if they do not write in 5 minutes.
I do not find an example in bot-framework documentation and, in stackoverflow there are not solutions for a started bot (I do not need it to start the conversation). Where do I need to create the code? I have an index.js and a dialog file. How can I set the timer and restart it when the user send a message?
I'm using directline.
Thanks
There are two different ways you can approach this, one for directline only using events and one for all channels using setTimeout. The directline solution requires some code on your webchat client, but the latter requires you to save the conversation reference and start a new bot adapter. Both approaches could work.
Directline Only
You need to set up your webchat client to set up the timer and send an event to your bot if no activities are sent before the timer expires. You need to create a custom store to do this. Here is an example I used in the past:
const store = window.WebChat.createStore({}, function(dispatch) { return function(next) { return function(action) {
if (action.type === 'WEB_CHAT/SEND_MESSAGE') {
// Message sent by the user
clearTimeout(interval);
} else if (action.type === 'DIRECT_LINE/INCOMING_ACTIVITY' && action.payload.activity.name !== "inactive") {
// Message sent by the bot
clearInterval(interval);
interval = setTimeout(function() {
// Notify bot the user has been inactive
dispatch.dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'inactive',
value: ''
}
});
}, 300000)
}
return next(action);
}}});
This will send an event to your bot with the name 'inactive'. Now you need to set up your bot to handle it. So in your this.onEvent handler you need to do something like this:
if (context.activity.name && context.activity.name === 'inactive') {
await context.sendActivity({
text: 'Are you still there? Is there anything else I can help you with?',
name: 'inactive'
});
}
All channels
As I'm typing this up, I'm realizing you should be able to emit the event from your bot itself and forego starting a new bot adapter instance. But I haven't tried that before, so I'm providing my existing solution. But you may wish to experiment with emitting an inactive event if the timeout is reached instead of the actions below.
That said, here is a solution you can use within your this.onMessage handler.
// Inactivity messages
// Reset the inactivity timer
clearTimeout(this.inactivityTimer);
this.inactivityTimer = setTimeout(async function(conversationReference) {
console.log('User is inactive');
try {
const adapter = new BotFrameworkAdapter({
appId: process.env.microsoftAppID,
appPassword: process.env.microsoftAppPassword
});
await adapter.continueConversation(conversationReference, async turnContext => {
await turnContext.sendActivity('Are you still there?');
});
} catch (error) {
//console.log('Bad Request. Please ensure your message contains the conversation reference and message text.');
console.log(error);
}
}, 300000, conversationData.conversationReference);
Note that you have to get and save the conversationReference if you go this route, so that you can call continueConversation if the timer expires. I typically do this in my this.onMessage handler as well just to make sure I always have a valid conversation reference. You can get it with the below code (I'm assuming you already have your conversation state and state accessor defined).
const conversationData = await this.dialogState.get(context, {});
conversationData.conversationReference = TurnContext.getConversationReference(context.activity);
Now as I mentioned in the first solution, I believe you should be able to send an inactivity event in your try block instead of initiating the bot adapter. If you try that and it works, please let me know so I can update this solution!

notifier.on click event is not fired in Windows Action Center

I am using the node-notifier package for notification but I have one problem. notifier.on click event is not fired in Windows Action Center
notifier.notify(
{
appId: "com.electron.demo", // Absolute path (doesn't work on balloons),
title: "Alert Message",
message: "Click to view",
icon: path.join(__dirname, 'msicon.png'),
wait: true,
timeout: false,
id: "demo app"
},
function(err, response) {
// Response is response from notification
if (err) {
reject(err);
} else {
resolve(response);
}
}
);
notifier.on("click", function(notifierObject, options, event) {
// Triggers if `wait: true` and user clicks notification
var request = new sql.Request();
let username = userName;
request.query("update alerts.dbo.groupmessages set isRead = 1\
where pk = '"+ recordset.recordset[i].pk + "'\
and userFK = (select pk from alerts.dbo.users where username = '"+ username + "')\
and groupFK = (select groupFK from alerts.dbo.users where username = '"+ username + "')", function (err, recordset) {
if (err) throw err
console.log(err, recordset, 'User shit');
});
function createWindow() {
// Create the browser window.
win = new BrowserWindow({
width: 400,
height: 400,
frame: false,
webPreferences: {
nodeIntegration: true
}
});
// and load the index.html of the app.
ejse.data('message', recordset.recordset[i].message);
win.loadFile('index.ejs')
}
createWindow();
});
});
});
notifier.on click event is not fired in only Windows Action Center. please let me know the reason and solution as well. Thanks.
Action Center requires separate implementation in native code, which node-notifier doesn't have.
You can try node-powertoast instead and use the onActivated callback:
npm i node-powertoast
const toast = require('powertoast');
toast({
title: "Hello",
message: "world",
callback: {
timeout: 5000, //keep-a-live in ms
onActivated: ()=>{ console.log("activated") },
onDismissed: (reason)=>{ console.log(reason) }
})
.then(()=> console.log("Notified")
.catch(err => console.error(err));
As for the reason:
You can see for other projects it's a significant undertaking and the following project, for example, seems to have Action Center support stuck in limbo for 2 years now: https://github.com/mohabouje/WinToast/issues/35 People trying to implement it themselves appear to have gotten stuck, and have had difficulty getting it implemented correctly.
It's just hard to do.
Notification doesn't get clicks because not all Action Center requirements are fulfilled.
In general Windows notifications have three types of activation: foreground, background and protocol.
In any case you will need to have the following:
Have a shortcut in Start Menu with AppUserModelId property. Please consult your installer on how to do it or use shell.readShortcutLink and shell.writeShortcutLink Electron API. Specifically WiX allows you to specify appUserModelId and toastActivatorClsid in options.
Specify AppUserModelId in the app.
app.setAppUserModelId('AppUserModelId');
Register a custom protocol and some reaction to it. For example like this:
app.setAsDefaultProtocolClient('example');
To use foreground or background you need to:
Have a shortcut in Start Menu with ToastActivatorCLSID property. See above on how to do it.
Use a project like electron-windows-interactive-notifications to register a COM server with the specified earlier ToastActivatorCLSID and a custom protocol of your choice and call:
registerComServer();
registerActivator();
I won't get deep into details on how to react to custom protocol but you will need to parse command line args in search for example: and also expect it in the second-instance hook if the app is already launched.
To use protocol type no extra actions needed.
After that even standard Electron notifications will get clicks from Action Center.
But how to use these protocols and get feature rich notifications?
Electron allows you to specify toastXml directly!
Let's say here's your notification. It will open https://google.com even if clicked from Action Center.
const notification = new Notification({
toastXml: `
<toast launch="https://google.com" activationType="protocol">
<visual>
<binding template="ToastGeneric">
<text>Wonderman meets Superwoman</text>
<text>In the eve of the new millennium, Wonderman challenges Superwoman to a bliniking contest.</text>
<text placement="attribution">Mars Press</text>
</binding>
</visual>
</toast>
`,
});
notification.show();
This notification simply opens Google. You can get more ideas at Notification Visualizer App

Twilio: Hangup a call in an existing conference, ERROR 20404

Following situation:
Someone called my Twilio Number
Twilio requested my url
Caller gets into a conference (don't starts until a second person join)
TwiML makes call to a Mobile
The Moblie dont accept the call
=> no second Person enters the conference so it wont stop and the caller is stuck there.
My solution is to end the whole call if this happens, I already know where to place the endCall function so this is not my problem. The function looks like this (You'll find it in the twilio API too):
client.calls(accountSid).update({
status: "completed"
}, function(err, call) {
if(err){
console.log(err);
}
});
My programm logic is fine, I see that this function is called at the right place but I receive this Error:
{ status: 404,
message: 'The requested resource /2010-04-01/Accounts/AC/Calls/AC.json was not found',
code: 20404,
moreInfo: 'https://www.twilio.com/docs/errors/20404' }
I already red whats at the moreInfo url but I disqualify
the solutions there. Maybe you have an idea whats the problem with this.
Twilio developer evangelist here.
You are almost all the way there. Your problem is that you are using your accountSid when trying to update the call's status.
You need to get hold of the callSid of the original call. You will find the callSid in the parameters that you receive in the incoming webhook when the person calls your Twilio number.
app.post('/calls', function(req, res, next) {
var callSid = req.body.CallSid;
// store callSid somewhere for use later
// return TwiML to set up conference and dial your mobile number
});
You'll need to save that callSid and then use it at this point later when you want to hangup the call.
client.calls(callSid).update({
status: "completed"
}, function(err, call) {
if(err){
console.log(err);
}
});
Let me know if this helps at all.

Waiting for email to arrive using node-imap

I'm using node-imap as a mail solution, but I need a way of waiting until an email arrives. In this post, someone referenced using the IMAP IDLE command to do this. I was wondering if anybody has had success with this, and how you would suggest incorporating that into the example code provided in the node-imap readme?
I decided to go with the inbox module. This provides a clear and quick solution through use of the call, client.on("new", function(message){.
I think good starting point is to research how is this method created in https://www.npmjs.com/package/inbox#wait-for-new-messages module.
Looks like this code emits the event of new.
As far as i understood the code of this module, they call the fetch command with intervals
For node-imap, "mail" event will be emitted when new mail arrives in the currently open mailbox.
You can listen to new mail event like this:
imap.on('mail', function(numNewMsgs) {
// Fetch new mail
});
You need to open a mailbox, which you want to listen for new messages. Here an example:
function listerBox() {
imap.once("error", console.error);
imap.on("ready", () => {
imap.openBox("INBOX", true, (error, box) => {
if (error) throw error;
console.log('Connected!')
imap.on("mail", () => {
console.log("New one!")
})
});
});
imap.connect();
}
listerBox()

Socket.io+SailsJS: Chat application-How to check whether the client is shut down,and make the user offline?

I am creating a multi-user chat application in node-web kit and SailJs and I was trying to implement login status of the users. User comes online when they open the application. The cases for the user to go offline are:
User clicks logout button
User closes the application window.
User turns his/her system off.
The logout status doesn't work when the user turns off their system. Here is a part of my code which I have written:
UserSocket.find({
companyId: user.companyId
}, function (err, sockets) {
if (!err && sockets != undefined && sockets.length > 0) {
socketList = _.pluck(sockets, "socketId");
sails.sockets.emit(socketList, 'userOffline', {
previous: user
});
}
});
Please help me in figuring out this issue. Thanks in advance.
Have you tried to use the onDisconnect method in the config/sockets.js ?
module.exports.sockets = {
onDisconnect: function(session, socket) {
//do your stuff here
}
}

Resources