smooshie

plug.dj api page

Jun 29th, 2012
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.13 KB | None | 0 0
  1. plug.dj has an API to empower Javascript developers to write extensions. The API is an event dispatcher that triggers after various events occur that developers might want to listen for. It’s simple to use and what you do with it is up to your imagination!
  2.  
  3. OVERVIEW
  4. There are two different parts to the API. There are functions that return various data, and there is an event dispatching engine.
  5.  
  6. DATA
  7. The data calls are as follows:
  8.  
  9. API.getAudience()
  10. Returns an Array of user objects of all the users in the audience (not including DJs).
  11.  
  12. API.getDJs()
  13. Returns an Array of user objects of the DJs. The first DJ in the array in the current DJ, and the rest are in order to the last DJ.
  14.  
  15. API.getUsers()
  16. Returns an Array of user objects of the DJs and audience. The first DJ in the array in the current DJ, and the rest are in order to the last DJ, and the audience is sorted by alphanumeric.
  17.  
  18. API.getUser(id)
  19. Returns the user object of a specific user.
  20.  
  21. API.getSelf()
  22. Returns the user object of the logged in user.
  23.  
  24. API.getModerators()
  25. Returns an Array of user objects of the moderators currently in the room.
  26.  
  27. API.getSuperUsers()
  28. Returns an Array of user objects of the Super Users currently in the room.
  29.  
  30. API.getHost()
  31. Returns the user object of the room host if they are currently in the room. Null otherwise.
  32.  
  33. API.getMedia()
  34. Returns the media object of the current playing media.
  35.  
  36. EVENTS
  37.  
  38. To add or remove an event listener, pass the name of the event and the function that will be called when the event occurs.
  39.  
  40. API.addEventListener(event, callback);
  41. API.removeEventListener(event, callback);
  42.  
  43. These are all the events that the API dispatches. The event names are all on the API object. Here’s an explanation of each one and what is passed to the callback function.
  44.  
  45. CHAT
  46. USER_SKIP
  47. USER_JOIN
  48. USER_LEAVE
  49. USER_FAN
  50. FRIEND_JOIN
  51. FAN_JOIN
  52. VOTE_UPDATE
  53. DJ_ADVANCE
  54. DJ_UPDATE
  55. WAIT_LIST_UPDATE
  56. VOTE_SKIP
  57. MOD_SKIP
  58.  
  59. CHAT
  60. This is called when an incoming chat arrives. It passes a chat object.
  61.  
  62. USAGE
  63. API.addEventListener(API.CHAT, callback);
  64. function callback(data)
  65. {
  66. data.type
  67. // “message”, “emote”, “moderation”, “system”
  68. data.from
  69. // the username of the person
  70. data.fromID
  71. // the user id of the person
  72. data.message
  73. // the chat message
  74. data.language
  75. // the two character code of the incoming language
  76. }
  77. ———————————————————————————
  78.  
  79. USER_SKIP
  80. This is called when the current DJ skips their own turn. It passes the user object of the dj who skipped.
  81.  
  82. USAGE
  83. API.addEventListener(API.USER_SKIP, callback);
  84. function callback(user)
  85. {
  86. alert(user.username + ” skipped their turn”);
  87. }
  88.  
  89. ———————————————————————————
  90.  
  91. USER_JOIN
  92. This is called when a user joins the room. It passes a user object.
  93.  
  94. USAGE
  95. API.addEventListener(API.USER_JOIN, callback);
  96. function callback(user)
  97. {
  98. alert(user.username + ” joined the room”);
  99. }
  100.  
  101. ———————————————————————————
  102.  
  103. USER_LEAVE
  104. This is called when a user leaves the room. It passes a user object.
  105.  
  106. USAGE
  107. API.addEventListener(API.USER_LEAVE, callback);
  108. function callback(user)
  109. {
  110. alert(user.username + ” left the room”);
  111. }
  112.  
  113. ———————————————————————————
  114.  
  115. USER_FAN
  116. This is called when somebody becomes your fan. It passes a user object.
  117.  
  118. USAGE
  119. API.addEventListener(API.USER_FAN, callback);
  120. function callback(user)
  121. {
  122. alert(user.username + ” is now your fan”);
  123. }
  124.  
  125. ———————————————————————————
  126.  
  127. FRIEND_JOIN
  128. This is called when somebody you are a fan of joins the room. It passes a user object.
  129.  
  130. USAGE
  131. API.addEventListener(API.FRIEND_JOIN, callback);
  132. function callback(user)
  133. {
  134. alert(“Your friend ” + user.username + ” just joined the room”);
  135. }
  136.  
  137. ———————————————————————————
  138.  
  139. FAN_JOIN
  140. This is called when somebody who is your fan but you are not a fan of joins the room. It passes a user object.
  141.  
  142. USAGE
  143. API.addEventListener(API.FAN_JOIN, callback);
  144. function callback(user)
  145. {
  146. alert(“Your fan ” + user.username + ” just joined the room”);
  147. }
  148.  
  149. ———————————————————————————
  150.  
  151. VOTE_UPDATE
  152. This is called when somebody in the room (including you) votes. It passes an object with a user object and the vote, -1 for negative, 1 for positive.
  153.  
  154. USAGE
  155. API.addEventListener(API.VOTE_UPDATE, callback);
  156. function callback(obj)
  157. {
  158. var vote = obj.vote == 1 ? “woot” : “meh”;
  159. alert(obj.user.username + ” voted ” + vote);
  160. }
  161.  
  162. ———————————————————————————
  163.  
  164. DJ_ADVANCE
  165. This is called when the dj advances to the next play. It passes an object with the array of user objects and the current media object. The first DJ in the array is the current DJ, and the remaining ones are waiting to play in that order. This is also called when the last DJ leaves the booth, in which case it passes null.
  166.  
  167. USAGE
  168. API.addEventListener(API.DJ_ADVANCE, callback);
  169. function callback(obj)
  170. {
  171. if (obj == null) return; // no dj
  172. var str = “”;
  173. var currentDJ = obj.dj;
  174. str += currentDJ.username;
  175. var total = currentDJ.djPoints + currentDJ.listenerPoints + currentDJ.curatorPoints;
  176. str += ” points: ” + total;
  177. str += “, fans: ” + currentDJ.fans;
  178. str += ” || ” + obj.media.author + ” – ” + obj.media.title;
  179. alert(str);
  180. }
  181.  
  182. ———————————————————————————
  183.  
  184. DJ_UPDATE
  185. This is called when the djs in the booth change, whether it somebody joins, leaves, etc. It returns an array of user objects of the DJs in order from playing to 5th position.
  186.  
  187. USAGE
  188. API.addEventListener(API.DJ_UPDATE, callback);
  189. function callback(djs)
  190. {
  191. var len = djs.length;
  192. for (var i = 0; i < len; ++i)
  193. {
  194. console.log(djs[i]);
  195. }
  196. }
  197.  
  198. ———————————————————————————
  199.  
  200. WAIT_LIST_UPDATE
  201. This is called when the users in the wait list change, whether somebody joins, leaves, is removed, or is added to the booth (and so removed automatically). It returns an array of the user objects in order from beginning to last in the wait list.
  202.  
  203. USAGE
  204. API.addEventListener(API.WAIT_LIST_UPDATE, callback);
  205. function callback(users)
  206. {
  207. var len = users.length;
  208. for (var i = 0; i < len; ++i)
  209. {
  210. console.log(users[i]);
  211. }
  212. }
  213.  
  214. ———————————————————————————
  215.  
  216. VOTE_SKIP
  217. This is called when the room votes down enough to skip the curent DJ. Null is passed.
  218.  
  219. USAGE
  220. API.addEventListener(API.VOTE_SKIP, callback);
  221. function callback()
  222. {
  223. alert(“The room has voted to skip”);
  224. }
  225.  
  226. ———————————————————————————
  227. MOD_SKIP
  228. This is called when a moderator force skips the current DJ. It passes the username of the moderator.
  229.  
  230. USAGE
  231. API.addEventListener(API.MOD_SKIP, callback);
  232. function callback(username)
  233. {
  234. alert(username + ” has skipped the current DJ”);
  235. }
Advertisement
Add Comment
Please, Sign In to add comment