Huddle01 🛠️ Building Powerful Communication Dapps - Akshit Gupta
HackFS 2023 · 9 Jun 2023 · 41:27
Akshit Gupta of Huddle01 shows how to add audio and video communication to a dapp using the Huddle01 iframe SDK and client SDK. After a short tour of the Huddle01 app, he demonstrates customizing the iframe with backgrounds, wallet options, redirect URLs and event listeners, with a code-along in a Next.js project. He then shows how to token gate a meeting so only holders of a given NFT or token can join, and shares project ideas for the HackFS hackathon.
Speakers
Topics
From HackFS 2023, hosted by ETHGlobal.
Transcript
Hello hackers, this is Akshutz from Huddle01, and today I'm going to be presenting a workshop on building powerful communication apps and tailoring dApp experiences with iframes and open gating. So we'll be going over two SDKs today. So one is the client SDK and the other one is the iframe SDK. So before going ahead with the workshop, first I'll discuss about the importance of audio video in the future. These days we see a lot of short video from platforms such as Instagram and TikTok where there's a very grave importance for audio and video where people communicate with each other, and users you know tend to retain 95% of the message when they listen it on video instead of text. So audio video is the future and it's really important, and that's what we power at Huddle.
So uh if you're not familiar with the Huddle01 web app, this is the this is what it looks like. So once you enter the Huddle01 web app, um this is what you get. You can have a chat, you can put your NFTs as PFPs, you can even live stream via live peer or even live stream it to YouTube, Twitch, etc. And we also have a mobile app which you can install on either iOS or Android. So it would be a really good if you you know go ahead and try it out before going into the SDKs because the uh the Huddle01 web app is one of the examples of the SDKs itself because it uses it. And uh once you get familiarized with the platform, it will be much easier for you to understand how the SDK works.
So I'll strongly recommend to go ahead and check it out. So at Huddle, we followed a three-pronged approach where we are relying on the DAP, which I just showed you, and we have our infrastructure, which are which is our STKs and our protocol. So our DAP is a progressively decentralizing meeting platform with all the Web3 native features like token gating, NFTs, SPFPs, and much more. And our infrastructure, our plug and play STKs are also there, which are supported for multiple platforms for web in which we have support for multiple languages, and then we have our protocol side which we are still working on, and we've recently made quite the development of the cryptoconomic side as well. Go ahead and check it out on Twitter.
So yeah, so at the end of this workshop, you'll learn how to do two things, which is mostly customizing your Huddle iframes to white label your dab according to your DAOs or NFT communities needs, and then you can even token gate your communication and implement access control to your dab. So first of all, we'll go we'll be going ahead and customizing our Huddle iframes, and uh I'll first quickly go over the docs and show you a quick walkthrough, then we'll do a short code along and see what we can do with the if M STKs. So I'll go head over to the Huddle01 docs.
So you can head over to Huddle01.com slash talks, and this is what you'll get. To check out the iframe part, you can head over to the quick integration and select iFrame here, and this is what you get. So these docs are we have support for vanilla as well as React, and uh you can head over to vanilla and check out the code, it's pretty simple. You can just include a CDN script and go ahead and use this. So what is possible with the iframe app will show you real quick.
So I have hosted this example app, which you can check out here. I've also pasted the links here. So you can head over to this link to check it out. And this is the link for the docs for the iframe. And you can even scan the QR code to head over to there. So once you you know use the iframe, um what is achievable is this something similar to this. So this is meet with wallet, and they integrated head over iframes and they had full customization as to what they can set as background. So over here, what he has done is that he's made the background transparent and is toggling uh his um dark mode and light mode, so it looks really good and blends really good with the platform.
So we're hoping to see some customization relating to the same. And uh this was uh like we did this in a closed way before. We shared it with some clients internally and tested it out. Now we have it out for you as well, and you can customize your iframes using the iframe SDK. So let's see how we can do that. So this is an iframe app that we've deployed. So as you can see, you have a lot of customization here. You can head over to this link and you know play around with it.
So you can have support for different wallets. So if I say on, then you have these many wallets which you can uh customize, then you can maybe unselect some if you want just MetaMask say so you can just check on MetaMask and you'll have it there. So this is how you can you know customize your uh iframe as well. And if you want to set the background on the iframe, what you can do is that uh I'll copy and lego uh so this is the background that I had uh this is for uh this is from the board apes website. So if you say you wanna build a metaverse sort of a thing uh for board apes, what you could do is that you could set a background here and you know customize the feel for board egg holders, and then um you can you know even set avatar URLs for your PFPs from here.
Then once you enter the dab, then you'll have some more customization. So I'll connect my wallet here and I start meeting. So once I'm in the meeting, I have the option to you know mute myself. So as you can see now, I'm muted, I can unmute, then even I can like share my screen, so it'll look like this, like I'll share real quick and show you. So this is how it works.
So you can uh control the Hado zero one web app from the parent app where the iframe SDK is installed and control it that way. Then I'll disable the share, and then if I can even add you know a redirect URL after the meeting ends, so say you want to you know redirect it somewhere to your own website, so I'll you know put in the Hard01 website link. So this is the Adult01 website, and if I put this on the redirect URL and save this, so now what will happen is uh once I click on end meeting for all it will redirect the whole application to Adon01. I'll show you that, and I can even send reactions from there.
So you can select any reaction and send it. So this is how you can control the Huddle01 iframe from outside of the uh outside of the Huddle app. And once I click on end meeting for all, see it redirected me to Huddle01.call. So this is how uh the iframe works once you've implemented it. Now we'll be you know delving into how to code this using the iframe S to K. So if you're using the vanilla, for you to get access to methods for you know controlling the meeting, you'll have to include the CDN script inside your app, and you have to render out this iframe, and once you do that, you'll get access to this HIFrame object on which we have this iframe API method.
So using this, you can set different parameters. So like over here, we've set the initialize function where we entered the background, so you can do that, and you can have you you'll have access to different uh methods over there. So for today, we'll go in we'll be going over the React iframe and seeing how it uh how it can be implemented on a React app. So yeah, so the first thing would be to set up a React application. You can quickly do that using NextJS and then the second step would be to install the iframe STK onto your lab app.
And once you do that, you can just import the Huddle iframe React component and paste in the URL for the for the meeting link. And you can even give it you know class names so it has full CSS support here as well. And once you do that, you'll have access to instance methods from the iframe API which you can directly import from the STK and you can then call methods such as initialize and on in the initialize uh you can send an object where you have different attributes that you can set as we saw before uh on this application, like you have these different re redirect URL on leave and background. So these are all the attributes that you can set to the object.
So this is how it works, and uh let's head over to the port. So this is what the code looks like. So this is a basic React page in NextJS. We have set up a simple NextJS project, and this is the same port as uh the one I just showed you, this one. So what we're doing here is we are just importing the Huddle iframe React component from the STK and rendering out in our marker, and we've pasted um the iframe.huddle.com link here so that you can just host any meeting. So if you'd like to you know have a specific room ID, you can even do that.
You can head over to iframe.com and like if I show you this, so this is iframe.dl01.com and once I this and you know create a meeting. So now that this meeting is created, I can simply paste this URL in my code as well. So if I paste this in my code right here, that will also work.
So it'll redirect me to the URL uh inside the iFrame. So this specific room ID I will be able to join uh in the icone itself. So this is how it's working, and then we have a couple of other things such as iframe API. So if you check this out, uh we have this initialized method being called on the iframe. So if I just remove all this, I command this for now, and if I space and press control space, I have access to these properties. So you can mention a background here.
So I've uh added this pixum photos URL, which you know generates a random image whenever it's called. So that's what you see here in the browser. Yeah, so as you can see, we have this random image popping up here every time we refresh. So this is where the Pix uh photos API. So we just paste this as a background URL and it works really good. Then you can even specify different wallets that you want.
So if you if I go ahead and type this, so you have access to all uh you have access to all the uh and it'll show you in code, yeah. So if you select wallets here and press control space, so you'll have access to different wallets which you want to show. So if you specify star here, it'll show all the wallets uh that we had so it'll show something like this, and if I select a specific wallet, then it will show me that particular wallet. So say I said MetaMask, so it'll just show me this MetaMask thing over here.
So this is how you can customize the wallets, and you must be thinking what this you use event listener part is. So we have different events inside the event listener. So I'll show you how that works. So if I head over back to the browser and to the docs, we have different events that you can listen to. So say you want to do uh a particular side effect on a particular event. So if you want to do you know um an alert when the room is joined, so you can listen to this room joined event um in this format, you can import the use event listener from the iframe SDK and uh paste the room joint event here and put whatever side effect you want inside the callback and you'll be good to go. So in our code, what we're doing is we're uh we're waiting for the lobby to be initialized.
So we're hoping to um see good use cases. Maybe you can create uh like create a meeting platform for a coil holders where if you own an NFT a BAYC NFT, then only you will be able to enter that meeting or something related to the same. But we we are hoping to look if you're using the iframe, we're hoping to look for really good, you know, innovative ideas here. So, yeah. So let's head over back to our slides, and yeah, so that that was all for iframes. Um, and if you like have any doubts related to the iframes or anything, you can you know join the Huddle 1 Discord and us there, or even the ETH global discord as well.
So now we'll go we'll go ahead and head over to the client SDK. And client SDK is for the users for the developers who you know want more customization than the iframe. So the iframe you know limits you to uh what you can see in the Hydro01 web app and it's good for people who just want a white labeled solution and don't want to, you know, code the code the web app from scratch and just want customization in the web app and have a meeting, so you get everything done for you. But if you want more customization and you want things to look and feel uh the way you have your design in the web in your own web app and uh you want more this one, like you want to move your viewports around and have a chat move around, something like that.
So if you want more customizations, client SDK is the way to go. So we'll we will go ahead and see how that works. So the Huddle O and SDK profers like offers multiple things. So if you want to um bring your own wallet and have your own identity management, you can do that as well. We'll see how that works in the news. And then we have different we have a state management solution built in in the Hudlow and SDK, so you don't have to you know build your own state management and handle the state for different peers and all that. We handle all that for you, and you have features like recording and live streaming.
So you can record like record a particular instance of your uh web app. So if you want that you want to record um from time t1 to time t10, then you can record that particular moment by entering a bot, so that can be done programmatically. We even have a video out for that, we'll link it somewhere now, and uh then you have communication, which is the basis of the SDK, so you can have audio video communication, you can have one to many communication, you can have many to many communication and so on. So we'll be delving into how we can do that.
So to understand the SDK before going to the code, I'll first explain how the architecture of the SDK works. So these states that you can see the the bold ones, so idle initialized, not joined, joining lobby, these are all the states of the application in which it can be. So you can listen to these states. So just remember these. So at one point of time, only uh one state is possible. So if it's an idle state, uh it can't be initialized.
So if you are in idle state and you call the initialize function, it will go to the initialized state, and in that particular initialized state, we'll have this not joined state, and then in that particular initialized state, you can you know call different methods to move around from the states. So say you're in the not joined state and you call the join lobby method, so it will pop you over to the joining lobby, and uh once the lobby is joined, it will pop you over to the joint lobby state, and then if you call the leave lobby function over there, then it'll you know get you right back to the not right state. So it's all based on a state machine, so you can move from one state to the other, and uh you can't simply you know jump up a state.
So if you're maybe in not joined state, and if you want to join go into the joint room state, you can't directly go there. You'll first have to uh enter the join lobby state and then move on to the joint one. So it's based on state machines and it is um very closed, so you have to follow a proper structure to uh get uh like navigate between different states. So this is how it works. So I think it's pretty clear from the idle to initialize function that you just have to call the initialize, and to call the initialize function, you'll also need to supply it with the project ID. So I'll show you that as well.
So if you head over to the docs and you head over to the API key section, you can just connect your wallet here, and once you connect your wallet, so you will have access to the project ID, then API key and a white estate domain. So if you're working on local, you won't really need to you know use the white tested domain, so you can just skip that. So you can copy your project ID and use it in the initialize function. So if I show you how the initialize function works, so you can head over to the user no one hook in which you can get the initialize function, and this is how it works.
So you can just import user01 from the React SDK, and once you get the initialize function, you can call it inside a use effect and put a project ID there which you get from the API key section. So this was the API key section, and if you want to you know use the create room API or maybe a token gating API, um, and we saw one for iframes as well. So you for that you'll require an API key. So if you if you want an API key, that is also provided here, so you can just copy the API key from here and use it in your app and call different APIs.
So this is how this works. So once you initialize your DAP with the project ID, the next step is to join a meeting room. So for joining the meeting room first, you have to join the lobby, and to join the lobby, you'll need a room ID. So to get a room ID, you have to uh you have to call the create room API route, which is called using the API key itself. So I'll show you how that works. So over here, what you can see is that we have this API.001 route and we we're calling the create room.
So in the create room, you have to specify your API key in the headers. So it looks something like this. You can just use XAPI key authentication and provide the API key value here, which you get from the docs we saw before. And once you call this, uh you get this room ID back. So using this room ID, you can join a lobby, then join a particular room. So if we head over to the docs. So this room ID is the one that you get by calling the insomnia route.
And to you know you have to call this route um on your back end. So I'd suggest you uh call this on your next.js um server side, and that will be great because you don't want to expose your API key on the front end. If you do that, then like uh your API key will be exposed and uh someone might you know use your API key and exhaust the parse. So I'd suggest you use an XJS server to uh call this API uh API call and get the room ID and then you can communicate the room ID back to your front end. So this room ID is uh then used in the join lobby method to join the lobby, and then we enter the join lobby state.
And in the join lobby state, then you can you know toggle your cam your mic, then fetch your video stream and all that so we also have an example app out for that I'll show you that let me just get the URLs yeah so if you head over here this is the example app for react uh next years and you can you know use this to test it out and how the functionality is working so it's based on the state machine itself so right now initially we are in the idle state and to get to the initialized state you can provide the project ID which you'll get from the dog so I'll do this again and once I have the project ID I can supply it over here and initialize so as you can see now we're in the initialized not joined state which is this one so we we are initialized but not joined so to join the room what you'll have to do is you have to paste in the room ID which you created using the same project ID so you put in the um put in the room ID and join the lobby and as you can see you were in the joining lobby state and now you're in the join lobby state so you have access to different methods over here.
So you can fetch the video stream, fetch the audio stream and all that. Right now I won't be going ahead with that as uh this meeting is being recorded and my camera is being accessed elsewhere. So it won't work. So I'll just join the room directly. And as you can see now we are in the joined room state. And in this joint room state, you'll have access to different other different methods. So if you would have you know enabled the audio stream before, you would have access to graduescam, and if you've enabled the mic before, then you'd have access to preduce mic, which basically means like sending your video and audio over to the other peers. So this is how that works, and you'll have also have access to the start recording method.
So this is how the flow works, and uh this is the basic overview of why you need the client SDK. So as you can see, this is all customized, you don't have any UI. Uh this is all just sample code, so you can just code out your own uh web app from scratch and have full customization towards what you want to do. So these are some really good client SDK examples we've seen. So these this is one of our clients called Parallax, and they've created this video meeting tab using the client SDK itself. So as you can see, they've customized the whole UI here, and you know they even have chat and um they they like created the whole UI from scratch and use the client SDK and they even have a live stream option where you can live stream by Addle.
So yeah, these are some these are a couple of ideas that we have. Uh okay, one idea is missing over here, so I'll quickly paste that in. Okay, yeah for now you can check the out these ideas so a metaverse where ape coin holders can join you know a token gated call which I mentioned before so if you're using the ice frame SDK then we can do pretty cool things with this and for um we'll also be seeing um what you can do with the client SDK using the auth package so uh let's go over that first so if I head over to the STK code so let me give a quick walkthrough how we are working with that so as you can see um we've installed the HuddleO and React package here so if we check out the imports this is the Huddle and React and you can even you know clone this app using using the CLI tool so if you just type in npx create01 you'll have uh access to all these example apps so you can just uh import use one from IDL01 React and then um what you can do is you have the initialize function as we showed before and this is how the code flow looks so one cool thing over here is that in your JSX what you can do is you can do conditional things based on the methods so if I check out any button in my app.
Okay, let's check this button out. So we have the set display name function. So each and every method in the Huddle of an STK has a attribute called is callable. So if you have you can just check the iscollables value if it's true, then the function would be callable. So you can you know toggle states based on that, show a different UI if you want. So as you can see, join room also has this callable property. So you can use this to you know conditionally render UIs and do a lot of stuff. So this is one thing, and I think we went over all the flow for initializing and joining lobby and then eventually joining the room.
So you can do that uh using leave room as well. Like you can leave the room of using this method uh once you join the room. Then we also have event listeners placed. So as we saw before in the iframe SDK as well, you have access to these events which you can you know use to have side effects run. So I'll also head over to the docs and show you that. So over here, if you go to events, then you have access to all these events inside the um React SDK.
So you can just listen to this lobby joint event in this way. You will have this huge event lister and you can just paste in the event here and call whatever side effect you want inside this call pack function. So this is how it's also go over how you can you know have a token gated meeting uh using the React STK or the Tite STK. If you're using Vanilla, we also have support for that, or even if you're using React Native for mobile apps you can even use that. So what we'll do is I'll refresh this and we are gonna create a token gated room.
So I'll head back over to Insomnia and over here we'll create a token gated row. So in this you can call this create room route and you know have this um have these attributes here. So here what we've mentioned is a title. Uh so I have a Pachibin, a patchy little budgie over here and quickly show you that. So if I go to NFTs, okay I'll switch this. And now I hope my NFT so I have this NFT and so we're gonna use this NFT to token gate the call.
So if you check here, you'll find the contract address of this NFT. You can even use a different API to do that, okay. Um I'll share the browsers. Yeah, so as you can see um in my MetaMask I have different NFTs. So we're gonna token gate the NFT to token gate the room using this NFT. You can find the contract address over here, and using this contract address you'll be able to tokenate the meeting. So you will head back over to the insomnia and here you'll you can see we've mentioned the contract address.
So this is the contract address of the NFT, and you can then use um just set the chain which you wanna do it, and you have you also have to set the token type. So this particular NFT is an ERC721. So we're we've put the token type here, and now you can you know tokenate the call. And if you want to you know fetch your NFTs, you can even use um I'm using NFT port over here, so you can just send this out and you know paste your address here and get access to the NFTs inside your inside your wallet. So you can even use this.
So for now we'll use this NFT. So now we have this room ID over here, and you can use this room ID um inside your web app where you're using the client SDK. So I'll head back over to the example app. So this is the example app. I've pasted in the room ID here, and if you use the project ID, I'll go ahead and paste in my project ID again. So once I get the project ID, I'll paste it here and initialize.
So right you have this access token field here as well. So if you want to, you know, implement like right now, I'm I I didn't connect my wallet to this tab, so there is no way of knowing that if I am authorized or not. So if I try to join the lobby, it will show me an error. If I do this now it says join lobby failed, that is because um because I didn't pre um like specify an access token and it is a token gated meeting, so it threw me an error. So if I try to, you know, if I want to generate um access token for myself using my wallet, you can head over to this auth simulator.
I will quickly show you that. So this is an npm package. Um yes, so you can go ahead and install this package, and using this package, you'll be able to you know authorize your user to um authorize your user to the huddle stk. So it's very simple to use, you just have to install the auth package and you'll get access to these methods from the auth package, and once you get the wallet address of the user, you can then use that wallet address to generate a message, and once you have the message, you can then sign the message using whatever you want.
So we've implemented VACNE over here, so you can just use use sign message and sign the message, and once you do that, you get a signature back, and using the signature uh you can get an access token by calling the get access token. So to simulate how this works, I'll show you an example. So if you head over to the auth simulator, you can connect your wallet here and disconnect this because it's connected to the wrong wallet. So this is some other wallet.
I'll connect it to my main account. Yeah, now we're connected to. Yeah, now we're connected to our main account. And once I click on get message, you get this message, and you have to sign this message using the sign message method. And once you do that, a MetaMask notification will pop up, and you can sign this. So once you have the access token.
Now if you head over to your dab and paste in the access token and join lobby, now you'll be able to join lobby. See now you've joined the lobby as this room was token gated. So using this access token, um the this access token was created using my wallet which had that particular contract address. That's how I was able to join this token gated meeting. Otherwise, I won't be able to. So this is how you can implement token gating on your um dab choosing the Huddle ST case, and um we are looking forward to seeing really good use cases of this.
So if you create a metaverse where you want to token gate a particular area, you can use this where people can join a particular area only when they have access to an NFT, and you can then share the audio video of that particular group of people if they own the NFT or not. So this is how it works. And I hope you've understood uh all and it was uh a little too much, I believe. But if you have any doubts, um you can head over to the Discord and ping us whenever you want, and we'll get we'll try to get right back at you. And yeah, that was all for the code along part.
I'll head head back to the slides, and these are a couple of ideas which you can see. So a metaverse where you know a coin holders can join a token gated call and interact in the metaverse. Then you can even have a marketplace platform renting out video conferencing and live streaming event recordings using FEM, so that's a really good use case as well. Then you can even build a social media platform which is you know built on file coin, maybe, and uh you can allow for real-time collaboration, file sharing and private communication, so it will be really good use case for data DAOs as well. So, yeah, we miss missed the second point, but that's alright.
You can check these out. Then these are some uh really good projects that we saw in a couple of hackathons before. So if you see check this out, we've uh like this is a customized i frame where uh you have a different background there, and we can we'd like to see some use cases such as this. Then like we have different other integrations. This was a client SDK integration, so this is really cool as well. So we'd love to see projects like which utilize in an innovative way rather than just cloning the apps and uh changing a few things. We'd like to see some really good innovative use cases of how the L SDKs can be used and uh where you can conduct audio video calls um and uh have people communicate with each other synonymously.
So yeah, so let's connect if you have any doubts or if you want to connect with me here are um here are my socials, so feel free to uh connect with me anytime. So that was all for today, and I hope you learned something and we hope to see really good projects coming out of HackFS. Kudos.
