README
Foreword
This was created as a response to the massive lack of libs/support presented in the MPP dev community. I intend to maintain and improve it for the foreseeable future.
Installation
Node.js 12.0.0 or newer is required.
npm install multiplayerpianojs
Example Usage
More seen here
const MPPClient = require('multiplayerpianojs')
const mpp = new MPPClient()
//const mpp = new MPPClient(SCOCKS/HTTPS PROXY HERE) alternatively
mpp.connect()
mpp.on('connected', () => {
console.log('bot connected')
mpp.setName('Mr Roboto')
mpp.setChannel('my room')
.then(() => console.log('Channel Set!'))
})
// These are chat messages
mpp.on('message', msg => {
if (msg.content === '!ping') {
mpp.sendMessage('Pong!')
}
if (msg.content === '!disconnect') {
mpp.disconnect()
}
if (msg.content === '!kickme') {
mpp.kickUser(msg.user.id)
}
if (msg.content === '!givemecrown') {
mpp.giveCrown(msg.user.id)
}
if (msg.content === '!allrooms') {
console.log(mpp.rooms)
}
if (msg.content === '!play') {
mpp.playMidi(__dirname + '/midi/test.MID')
}
})
mpp.on('userJoin', user => {
console.log(`user joined: ${user.name}`)
mpp.sendMessage(`Welcome ${user.name}`)
})
mpp.on('userLeave', user => {
console.log(`user left: ${user.name}`)
mpp.sendMessage(`Goodbye ${user.name}`)
})
Methods/Functions
- connect()
Connects bot to the WS
- disconnect()
Disconnects bot to the WS
- setChannel(String name)
Sets the current channel
Returns: Promise
- sendMessage(String message)
Sends message in channel
Returns: Promise
- setName(String name)
Sets the current name
Returns: Promise
- moveMouse(Int x, Int y)
Moves mouse position
Returns: Promise
- kickUser(String userID, Int timeInMS)
Kicks user from room for a specific time, must be owner
Returns: Promise
- giveCrown(String userID)
Gives crown to specific user, must be owner
Returns: Promise
- startNote(String Note, Int Velocity)
Play a specific note
Returns: Promise
- stopNote(String Note)
Stop a note from playing
Returns: Promise
- playMidi(String path)
Plays a midi file
Returns: Promise
- stopMidi()
Stops the playing of a midi file_
Returns: Promise
Events
- connected
Fired on bot connection to websocket
- disconnected
Fired on bot disconnect to websocket
- userJoin
Fired on user join
Callback: Object
- userLeave
Fired on user leave
Callback: Object
- notePress
Fired on note press
Callback: Object
- error
Fired on error
Callback: String
- Message
Fired on chat message recieve
Callback: Message Object
- midiLoaded
Fired on midi file loaded
- midiPlaying
Fired on midi file playing
- midiEvent
Fired on midi file event
callback: event object
- midiEnded
Fired on midi file end
Properties
- room
Object containing all users in room + room name
- rooms
Array of all the rooms and their counts
- proxy
Currently connected proxy
Dependencies
- https-proxy-agent
- socks-proxy-agent
- ws
- midi-player-js
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
All code must follow standardjs principles. Keep documentation thorough as well.