WebRTC - RTCDataChannel.readyState is not 'open' - javascript

I'm trying to make a text chat, using WebRTC and data channels, but like the title suggests, it isn't working.
And the peer that's being contacted never has ondatachannel being called. Where did I screw up?
Code: https://hastebin.com/satoweyige.php

Do not use {RtpDataChannels: true} and burn the book you found that it. This is non-standard and known to lead to errors.

Related

discord.js error 50001: Missing Access while creating slash commands

I've been trying to make slash commands in discord.js for a discord bot (a personal project to practice coding) and I've been getting this error, with no success in trying to solve it... I've already given OAuth2 access to the command creation, so I have no idea what I'm doing wrong.
https://pastebin.com/y5g2P8Cm
DiscordAPIError[50001]: Missing Access
at SequentialHandler.runRequest (C:\Users\Nicolò\Desktop\colino-bot\node_modules\#discordjs\rest\dist\lib\handlers\SequentialHandler.js:198:23)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (C:\Users\Nicolò\Desktop\colino-bot\node_modules\#discordjs\rest\dist\lib\handlers\SequentialHandler.js:99:20) {
rawError: { message: 'Missing Access', code: 50001 },
code: 50001,
status: 403,
method: 'put',
url: 'https://discord.com/api/v9/applications/914567485158744104/guilds/251345856169508864/commands'
}
EDIT: Solved, apparently I just removed some permissions and now it works... I have no clue why it works this way, but ok.
When your bot is added to a server via an OAuth2 link it requires the application.commands to be able to register slash commands.
Even if you update the scopes in your link the bot has to be removed and then re-added back to the server with the new link for the changes to take effect.
Learn more about discord OAauth2 scopes here
EDIT: Solved, apparently I just removed some permissions and now it works... I have no clue why it works this way, but ok.
Anyone encountering this problem the solution is pretty simple.
It DOES NOT depend on the permissions that have been provided to the bot when creating the OAuth2 link to invite the bot. It is not enough to just select the bot option, the applications.commands option also needs to be selected, see captured screenshot in the following link

WebRTC - What is the proper way to create RTC Data Channel?

I work on WebRTC JS app and stcuk at a point where I need to crete a data channel. I have this part of code which actually works but openRTCDataChannel method is being executed twice:
this.myRTCConnections[id][hash]=window.RTCPeerConnection?new RTCPeerConnection(this.RTCConfiguration,{optional:[]}):(window.mozRTCPeerConnection?new mozRTCPeerConnection(this.RTCConfiguration,{optional:[]}):new webkitRTCPeerConnection(this.RTCConfiguration,{optional:[]}));
this.myRTCConnections[id][hash].ondatachannel=function(event){This.openRTCDataChannel(event,id,hash)}//first calling of openRTCDataChannel method
this.openRTCDataChannel(false,id,hash)//second calling of openRTCDataChannel method
this.openRTCDataChannel=function(event,id,hash,onOffer,initiator){
var RTCDataChannelOptions={reliable:true},This=this
if(!this.myRTCDataChannels[id])this.myRTCDataChannels[id]={}
this.myRTCDataChannels[id][hash]=event&&event.channel?event.channel:this.myRTCConnections[id][hash].createDataChannel("myDataChannel",RTCDataChannelOptions)
this.myRTCDataChannels[id][hash].onerror=function(error){log(error)}
this.myRTCDataChannels[id][hash].onmessage=function(e){This.handleIncomingRTCMessage(e.data,id,hash)}
this.myRTCDataChannels[id][hash].onclose=function(e){This.onSignalingServerLeave(false,id,hash)}
this.myRTCDataChannels[id][hash].onopen=function(e){This.onRTCDataChannelOpen(id,hash,onOffer,initiator)}
}
If I comment first or second calling if openRTCDataChannel method some of my peers can exchange data between themselves and some can not.
So the problem is that if I want my code to work I need to execute openRTCDataChannel method twice in two different ways. What am I doing wrong and what is the best way to start data channel which would work in all browsers?
Any help appreciated!
Ok. SO it seems I have found out what is wrong here.
Peer that initiates the connection and sending an offer should create data channel this way:
this.openRTCDataChannel(false,id,hash)
And another peer which accepts the offer and sending an answer should use this:
this.myRTCConnections[id][hash].ondatachannel=function(event){This.openRTCDataChannel(event,id,hash)}
I checked this in Mozilla and Chrome and it worked for me. Correct me if I am wrong.

botframework v4: send slack blocks in channelData property not working

I'm using botframework v4 to deploy an azure bot. The bot will be used on both Teams and Slack channel.
The bot needs to send blocks layout to slack users. But when I put the blocks in channelData property, it always returns below issue
Error: Invalid ChannelData
at new RestError (D:\home\site\wwwroot\node_modules\#azure\ms-rest-js\dist\msRest.node.js:1397:28)
at D:\home\site\wwwroot\node_modules\#azure\ms-rest-js\dist\msRest.node.js:1849:37
at process._tickCallback (internal/process/next_tick.js:68:7)
Here is the code snippet
await context.sendActivity({
"channelData": {
"blocks": [
{
"type": "image",
"image_url": "https://api.slack.com/img/blocks/bkb_template_images/beagle.png",
"alt_text": "Welcome to my bot"
}
]
}
}
)
I've tried adding "text" property to the payloads, the text will be replied by the bot correctly, but no image shows after the text.
And I've also tried other several ways, like put the blocks to attachments property, all didn't work.
Does someone knows what is the correct way to pass the blocks data to Slack?
Thanks.
As I posted in the issue that #ErikKalkoken linked to, this feature currently isn't available. You have a couple of options:
Wait for the feature to be implemented. However, as one of the developers states:
Based on my understanding of the roadmap right now, the activities endpoint will not be updated with support for Block Kit any time soon.
Since it looks like you're looking for a javascript answer, you can use the BotKit Slack adapter

Discord Bot Can't Get Channel by Name

I have been making a discord bot and wanted to make it send a message to a specific "Welcome" channel. Unfortunately, I have been unable to do so. I tried this.
const welcomeChannel = bot.channels.get("name", "welcome")
welcomeChannel.sendMessage("Welcome\n"+member.user.username);
However in this "welcomeChannel is undefined".
Edit:
I tried using
const welcomeChannel = bot.channels.get("id", "18NUMBERIDHERE")
welcomeChannel.sendMessage("Welcome\n"+member.user.username);
but this is still undefined, strangely
You should use the channnel id instead of it's name.
How to get the channel id of a channel:
Open up your Discord Settings
Go to Advanced
Tick Developer Mode (And close the Discord settings)
Right click on your desired channel
Now there's an option Copy ID to copy the channel id
Also checkout the discord.js documentation for (channel) collections
Furthermore your approach won't work because .get wants a channel id (see the linked documentation above). In case you REALLY want to get an channel by its name, use .find instead for that.
This is however a really bad idea in case your bot runs on more than one server since channel names can now occur multiple times.
You can also use
bot.channels.find("name","welcome").send("Welcome!")
I tried a lot with the same error, and that's how I fixed it. I used client as my Client().
client.channels.cache.get("18NUMBERIDHERE").send("Welcome!");
Your error could come from the fact that you're using bot.channels.get(), which isn't the best idea, because discord.js isn't very friendly when it comes to using .send() on multiple items.
Instead, try to use member.guild.channels.find("name", "channel").send();, if possible. If this is in the client.on("message"), then simply use message.member.channels.find("name", "channel").send();
Sidenote: My memory is mixed up, so if that doesn't work, try .get() instead of find.

chrome.identity.getAuthToken returning "bad client id: {0}" error

I'm trying to use chrome.identity.getAuthToken to get a token, but every time I try this error shows up:
OAuth2 request failed: Service responded with error: 'bad client id: {0}'
I have no idea why this is happening. The client ID I put in manifest.json is exactly the same as the one on the Google Developers Console, and the correct scopes is also included:
oauth2: {
"client_id": "NUMBERS-NUMBERS&LETTERS.apps.googleusercontent.com",
"scopes": ["https://www.googleapis.com/auth/SOME_SERVICE"]
}
The extension is up on the webstore, and I don't see why it is still giving the bad client ID error.
What is possibly causing this error? What am I missing here?
Just as a note for myself and for someone run into.
I have encounter this problems with chrome app , the answers is not my problem ,and finally I found the solution for my problem but produce the same error as the question.
As https://developer.chrome.com/apps/app_identity#client_id say is much special for chrome apps, you have to create a separate client id for your chrome app.
Go to the "API Access" navigation menu item and click on the Create an OAuth 2.0 client ID... blue button.
Enter the requested branding information, select the Installed application type.
you must to choose Installed application an set you Application ID.
what's your Application ID ?
chrome-extension://your application id
chrome-extension://gfmehiepojbflifceoplblionpfclfhf/
I overcomed this problem by setting up the email address and product name in "Consent screen" in the Google Developer Console.
Please refer to https://developers.google.com/console/help/new/#userconsent for detail.
I had a similar problem. Everything seemed to work fine on my own laptop, but when i ran it on another device i got that "bad client id" error.
My problem was that the client-id changed from one device to another, as i did not yet upload my extension to the chrome store.
To overcome that problem, i followed the instructions of How to change chrome packaged app id Or Why do we need key field in the manifest.json?.
You need to create a key to keep the client-id persistent through all devices.
Hope that helps finding the right answer for people with the same issue quicker.

Categories