Skip to content
Matt Thompson edited this page Feb 16, 2023 · 43 revisions

getting started

dependencies

  • firebase (realtime database and auth libraries)

ftapi.init(firebaseConfig)

Inits firebase app, and starts firetable. firebaseConfig should be an object containing with the following:

var firebaseConfig = {
 apiKey: "xxxxxxxxxxxxxxxxxx",
 authDomain: "xxxxxxxxxxxxxxxxxx.firebaseapp.com",
 databaseURL: "https://xxxxxxxxxxxxxxxxxx.firebaseio.com"
};

events

ftapi.events.on("newChat", callback(newChatData) )

fires for every new chat message. callback returns data on the new chat message

// example chat data
{
  id: "LsEw02rY37dqP9lnCdLUsJuns9U2",
  name: "matt",
  time: 1587142349431,
  txt: "mr wavehair keepin you quiet",
  chatid: "-M582_7ryxq3bMD0oorx"
}

ftapi.events.on("userJoined", callback(userData) )

ftapi.events.on("userLeft", callback(userData) )

ftapi.events.on("userChanged", callback(userData) )

ftapi.events.on("usersChanged", callback(data) )

fires every time the userlist changes. callback returns entire userlist.

// example users list data
{
  FPSkbyoRxdMBpijIuYtFZrDAK852: {
                                  mod: true,
                                  username: "Andrew"
                                },
  LsEw02rY37dqP9lnCdLUsJuns9U2: {
                                  mod: true,
                                  supermod: true,
                                  username: "matt"
                                },
  OiJ7rcoNaNdvk3KlFGUJx1Fqjer2: {
                                  hostbot: true,
                                  mod: true,
                                  username: "jarvis"
                                 }
}

ftapi.events.on("newSong", callback(data) )

Will fire on every new song. Callback contains data about playing song

{
  artist: "Jagwar Ma",
  cid: "1vU6a7Haw78",
  djid: "zc2ZsfVjZ1hlYMWtYRc9tXUG7ZJ3",
  djname: "scytheria",
  duration: 216,
  image: "https://i.ytimg.com/vi/1vU6a7Haw78/mqdefault.jpg",
  key: "-M2mTXNvadPMFi_Qed5D",
  postedDate: 1359554375000,
  started: 1587153700688,
  title: "The Throw",
  type: 1,
  url: "https://www.youtube.com/watch?v=1vU6a7Haw78"
}

ftapi.events.on("tagUpdate, callback(data) )

will fire if the hostbot sends out corrected tag info or play stats

// example tagUpdate data
{
  adamData: {
              artist: "Tallsaint",
              last_play: "2019-11-22T00:56:45.403Z",
              last_play_dj: "Chris",
              playcount: "5",
              track_id: 41735,
              track_name: "Model Effect"
             },
  cid: 708643411
}

ftapi.events.on("newHistory", callback(newHistoryData) )

ftapi.events.on("newNewMusic", callback(newNewMusicData) )

ftapi.events.on("tableChanged", callback(data) )

ftapi.events.on("spotlightStateChanged", callback(spotlightPosition) )

ftapi.events.on("playLimitChanged", callback(playLimit) )

ftapi.events.on("waitlistChanged", callback(waitlistData) )

ftapi.events.on("newTheme", callback(theme) )

ftapi.events.on("danceStateChanged", callback(danceBool) )

ftapi.events.on("screenStateChanged", callback(screenBool) )

ftapi.events.on("colorsChanged", callback(colorData) )

ftapi.events.on("playlistChanged", callback(playlistData, listID) )

fires when the currently selected playlist is updated, or if a different playlist is selected. callback contains the playlist and the listID

ftapi.events.on("blockedUsersChanged", callback(blockedUsers) )

ftapi.events.on("loggedIn", callback(userData) )

Fires when user logs in, contains object with some data about user

ftapi.events.on("loggedOut", callback)

ftapi.events.on("authReconnected", callback)

ftapi.events.on("authDisconnected", callback)

actions

ftapi.actions.sendChat(txt, cardid[optional])

ftapi.actions.switchList(listID)

ftapi.actions.createList(listname)

returns listID for created list

ftapi.actions.deleteList(listID)

ftapi.actions.addToList(type, name, cid, destListID[optional], callback[optional])

returns trackID for added track

ftapi.actions.moveTrackToTop(trackID, previewTrackID[optional], previewChangeCallback[optional)

moves track to top of selected list. optionally, if you pass the trackID of a currently playing preview track, its new trackID will be returned in the callback

ftapi.actions.shuffleList(previewTrackID[optional], previewChangeCallback[optional)

optionally, if you pass the trackID of a currently playing preview track, its new trackID will be returned in the callback

ftapi.actions.reorderList(arrayOfTrackIDs, previewTrackID[optional], previewChangeCallback[optional)

arrayOfTrackIDs should be an array of the current track IDs of the currently selected list in the order you'd like to change them to. Optionally, if you pass the trackID of a currently playing preview track, its new trackID will be returned in the callback

ftapi.actions.removeDuplicatesFromList()

ftapi.actions.moveTrackToBottom(trackID, callback[optional])

ftapi.actions.deleteTrack(trackID, callback[optional])

ftapi.actions.unflagTrack(trackID)

ftapi.actions.blockUser(username, callback(responseString) )

ftapi.actions.unblockUser(username, callback(responseString) )

ftapi.actions.editTrackTag(trackID, cid, newTag)

ftapi.actions.changeName(newNameString, callback)

Changes username of currently logged in user. Callback contains error string if username is taken or is invalid. (All usernames must range between 1 and 22 characters in length and contain only numbers 0-9, letters from a-z, and underscores). If no error string passed in callback, name change was a success!

ftapi.actions.logOut(errorCallback)

ftapi.actions.logIn(email, password, errorCallback)

ftapi.actions.resetPassword(email, errorCallback)

ftapi.actions.signUp(email, password, username, errorCallback)

ftapi.actions.unbanUser(userid)

ftapi.actions.banUser(userid)

ftapi.actions.modUser(userid)

ftapi.actions.unmodUser(userid)

lookup

ftapi.lookup.card(cardid, callback)

ftapi.lookup.cardCollection(callback)

ftapi.lookup.userByName(username, callback)

ftapi.lookup.userByID(userid, callback)

ftapi.lookup.selectedList(callback)

returns the listid of the currently selected playlist

ftapi.lookup.allLists(callback)

Clone this wiki locally