for my school project i have to recreate Secret Hitler game using socket.io/express/vuejs2.
And at the moment I'm stuck at the part where i should create lobby that other people should be able to join. I used rooms for the lobby, but then i realized that it's not what i need. What i though of is when person creates a lobby, a name will be assigned to that specific lobby so other user will be able to join that lobby by inserting the name of it or using the link which would look something like that http://mygame.com/?lobby=ABCD. But if i got socket.io rooms correctly, i wont be able to do that, because you can't create unique rooms. Or I'm just dumb and haven't figured that out yet.
So my question is how could i implement lobbies based on my idea using socket.io and expressjs? What documentation should i read?
Try this Tutorial
https://www.youtube.com/watch?v=DvlyzDZDEq4
I know it is a zoom app but it will give you a basic idea on how to create rooms with node.js
Related
First i'm a node.js begginer. I have a chat app which i created with socket.io the concept is i make a single unique room after 2 users are paired. but want to know if is it necessary for me to delete the room after the 2 members leave or i just let it.
I don't even know if the rooms are taking storage and how much..
some one help me understand please.
Rooms are automatically created and deleted as users join and leave.
As for storage, socket.io doesn't use any storage during runtime, just memory. A single user or room shouldn't use any significant amount of memory.
This is the first time I would like to implement MongoDB as a database within one of my applications and I’m quite confused...
My application has its own User class which is represented at the end of this post(UML class diagram).
Since my User object has its own properties and methods I feel that creating a schema usually used with mongoose would mean duplicating code.
Am I really well understanding how MongoDB works?
Is it not possible to save my User object inside my MongoDB database without having to use a schema?
If I want to follow the MVC pattern how could I implement the MongoDB model with the class represented on my diagram?
Thank you for your help!
I am trying to get my bot to message two people but in the same chat window (like when you add a friend to a conversation). The only thing I've found is how to send to a single person by doing <client>.send(message); How could I add a second person to that conversation?
Any examples would be highly appreciated.
Discord.js doesn't really implement that because in Discord bots can't join Group DMs. You would need a self-bot (a bot that runs on a user account), but Discord doesn't want them to be used, so discord.js didn't make this options.
Therefore, at the moment there's no way to do that: the groupDMChannel class can't be used to create them, and since there's no method to do that from the client or from a DM channel I think you're stuck there :\
just taking a quick look at the Discord.js documentation, it seems they do have a GroupDMChannel class, and this seems to be what you want / need to use.
The two methods that stand out to me:
send
addUser
Where I'm assuming (I know I shouldn't!) that you have to call addUser first.
disclaimer: not going into detail, since I don't have experience using this particular module
In a node application serving websockets where users subscribe to several topics published and gets new updates on the topics in a real-time manner, whats the best way to store the topic-subscriber map?
Live Topics : Topic1, Topic2, Topic3, Topic4
User1 subscribes to Topic1,Topic2,Topic4.
User2 subscribes to Topic2,Topic4.
So there shall be a map object as follows
Topic1=>[User1]
Topic2=>[User1,User2]
Topic4=>[User1,User2]
So that when there is an update on Topic1, the application shall pass the update on User1's websocket.
The question : Is it good enough to keep the topic-subscribers map as an application variable (javascript object)? Or is it better to employ REDIS to manage this?
I also want to store the information in this map to analyse for the trends like Topic interest over time by geography. Hence, this data shall be copied to the original DB in the background.
I believe I should not be querying the database to find the current subscribers everytime there is an update on a topic.
As with what I managed to find, REDIS is an in-memory datastore. And the javascript application variable will also live on the RAM.
Whats the best way to go about it?
Performance as in the quickest update to the subscriber is desired.
Personally I believe it is better to do this in Redis, but only because sooner or later you're going to need more than one node as your application scales. The moment you do that you're out of NodeJS-land and trying to find some way to coordinate this work across a cluster. Redis is very well suited to this task.
That said, perhaps you should look at the ActionHero framework. Its chat module does precisely what you're trying to do. With very little code you can have WebSocket clients connect to one or more nodes in a cluster (coordinated by Redis) and join zero or more chat rooms, then receive the messages sent to those rooms. It could save you some time.
Intro:
I have a collection of players in my app, this is built using a schema and then passing some stuff into my node.js configuration, perhaps it's a bit more complex than that but I mean this is the basic idea of how mongoDB for nodejs works with models and collections.
So now in my database I have my DB name then collections then a collection of players, great now I can build an api and start making requests to GET and PUT from that collection.
Question:
My problem is in my stats app after week one's game was tracked I need to clear all the player attributes so that in week 2 it's fresh, but I would like to save all the stats for the players from week 1.
So due to my basic knowledge of how a collection is built I am thinking in order to build a new collection I need to define a schema, but perhaps there is another way, if not then the schema would have to be dynamic right? Well how do I build a dynamic schema to suit this problem?
Ideas:
Idea: The user clicks a button saying complete week 1, then the server takes all the data from the players collection and builds a
new collection named week 1 players?
Question: If the above is a good idea, how do I build a function to create a new mongoDB collection and save players_week1 into its
own branch?
Final Word:
So hopefully someone has an optimal solution and understands what I am talking about, in the mean time I am going to try and follow my idea and see if I can search the docs to find some answers. Thanks guys.