I'm creating a collaborative web music platform.
At present, i have a simple drum machine working locally, with a JSON file logging all the beats. i.e. after punching in the pattern, the code looks like this when logged to console. A scheduler and play function then iterates through and plays the beat if it's 'on' at the current beat.
"kick": [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
"snare": [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
"hat": [0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1],
"tom1": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"tom2": [0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0],
"tom3": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
So next i want to network this web app, so two people can edit the pattern at the same time. I'm really struggling and would love some help here. I've looked at meteor and sharejs, but have become quite confused.
How can i have a JSON file living on the server, which is edited by two users? (they will take it in turns to edit the pattern, like this game http://sharejs.org/hex.html#9TGAyPGFOy) This JSON file needs to be updated in the code at all times, so the latest version of the track can be played to both users.
Any tips would be great, i feel i'm overcomplicating myself here...
Thanks
I would suggest using Socket.io for this project.
You could have a simple socket server set up, with the following code:
(don't forget to
npm install --save socket.io
!)I basically just typed this into the answer box - this hasn't been tested or whatever, but I think it gives you a good idea of the fundamentals of the Socket.io library for your project.
As mentioned in my comments, I would not advise using *sync methods when doing filesystem operations. This method is a little easier to read but will lock the entire process while a file is read/written. This will lead to problems if there are more than a couple of users using the project. Look into the *async methods for ways to combat this. They're not much harder to implement.
Good luck!