├── README.md
├── d.js
├── dclient.js
├── djs.png
├── examples
├── .DS_Store
├── hackathon
│ ├── .DS_Store
│ ├── EXAMPLEREADME
│ ├── app.js
│ ├── node_modules
│ │ ├── .DS_Store
│ │ ├── .bin
│ │ │ └── express
│ │ ├── ejs
│ │ ├── express
│ │ ├── mongodb
│ │ └── now
│ ├── static
│ │ ├── .DS_Store
│ │ ├── d.js
│ │ ├── master.css
│ │ ├── nice.otf
│ │ └── node_modules
│ │ │ ├── .DS_Store
│ │ │ ├── .bin
│ │ │ └── express
│ │ │ ├── djs
│ │ │ ├── README.md
│ │ │ ├── d.js
│ │ │ └── package.json
│ │ │ ├── ejs
│ │ │ ├── express
│ │ │ ├── mongodb
│ │ │ └── now
│ └── views
│ │ ├── .DS_Store
│ │ ├── d.js
│ │ ├── index.ejs
│ │ ├── porntable.ejs
│ │ └── splash.ejs
└── turntable
│ ├── .DS_Store
│ ├── app.js
│ ├── node_modules
│ ├── .DS_Store
│ ├── .bin
│ │ └── express
│ ├── ejs
│ ├── express
│ ├── mongodb
│ └── now
│ ├── static
│ ├── .DS_Store
│ ├── bookfort.png
│ ├── d.js
│ ├── giggle.mp3
│ ├── js
│ │ ├── .DS_Store
│ │ ├── Jplayer.swf
│ │ └── jquery.jplayer.min.js
│ ├── mascot.png
│ ├── master.css
│ ├── nice.otf
│ ├── node_modules
│ │ ├── .DS_Store
│ │ ├── .bin
│ │ │ └── express
│ │ ├── djs
│ │ │ ├── README.md
│ │ │ ├── d.js
│ │ │ └── package.json
│ │ ├── ejs
│ │ ├── express
│ │ ├── mongodb
│ │ └── now
│ ├── opening.mp3
│ └── skin
│ │ ├── .DS_Store
│ │ ├── jPlayer_blue.monday_extd.psd
│ │ ├── jplayer.blue.monday.css
│ │ ├── jplayer.blue.monday.jpg
│ │ ├── jplayer.blue.monday.seeking.gif
│ │ ├── jplayer.blue.monday.video.play.png
│ │ └── spirites_blue.monday_2011.psd
│ └── views
│ ├── .DS_Store
│ ├── d.js
│ ├── index.ejs
│ └── porntable.ejs
└── package.json
/README.md:
--------------------------------------------------------------------------------
1 | ###DJS makes media-sharing sites easy to make!
2 |
3 | Check out the github
4 |
5 |
6 | ##What is DJS?
7 |
8 | DJS is a Node.JS module built on top of Now and MongoDB. It is a media distribution framework. Simply spin up a Node server and plug DJS in and serve up all sorts of media in real-time with no server-side Javascript necessary. Media can mean anything from YouTube videos, pictures, and even webpages. We also support a public subscription model and groups, for discriminating customers.
9 |
10 | Install from npm
11 | ----------------
12 |
13 | `npm install djs` or `npm install djs -g` for a global installation. You may have to also `npm install mongodb`.
14 |
15 |
16 |
17 | ##Public API
18 |
19 | ```javascript
20 |
21 | var server = express.createServer(...)
22 | var nowjs = require('now');
23 | var everyone = nowjs.initialize(server, {socketio:{"log level": process.argv[2]}});
24 | ...
25 | var dj = require('djs')
26 | dj.initialize(server, nowjs, everyone)
27 |
28 | ```
29 |
30 | Note: Any arguments with * are optional
31 |
32 | #Bare Bones Server Side Functionality
33 | ------
34 |
35 | now.SbroadcastMedia(mId, *roomId, callback)
36 |
37 | By default it tells all the clients to display whatever media is indicated by mId. Supplying the roomId will only display the media to users in that particular room. You must search for the mId you want using `SfindMedia`. The callback expects an argument `mediainfo`, which is a JSON object of this form. The callback has to be in the now space.
38 |
39 | ````javascript
40 | {
41 | path: path_to_media
42 | tags: [array, of, tags]
43 | metadata: JSON of your choice
44 | }
45 | ````
46 |
47 | now.SfindMedia(searchQuery, callback)
48 |
49 | Crawls the database for media with the searchQuery as part of the tag and passes the result to the callback function as an array of JSON objects of this form:
50 |
51 | ````javascript
52 | {
53 | path: path_to_media
54 | tags: [array, of, tags]
55 | metadata: JSON of your choice
56 | }
57 | ````
58 |
59 | now.SaddMedia(path, tags, metadata)
60 |
61 | Adds the media to the database. path is just the path to the media in question; tags is an array of strings. Metadata is a JSON object of your choice!!!
62 |
63 | now.SaddToRoom(roomId)
64 |
65 | Adds the user who calls this function to the room. If the room didn't exist before you made this call, you will create it.
66 |
67 | now.SleaveRoom(*roomId)
68 |
69 | By default, has the user who calls this function leave all the rooms, including the `everyone` namespace (i.e. a logout). When called with a roomId as an argument, has the user leave just that room.
70 |
71 | now.Sapply(functionName, *args, *roomId)
72 |
73 | By default, applies the callback function on all members of the `everyone` group, i.e. everybody who is on the server. Providing the optional `roomId` argument causes the callback to only be applied for members in the room. Note that the callback function must be in the now pocketspace.
74 |
75 | #Groups Server Side Functionality
76 | -----
77 | now.SaddUser(uId)
78 |
79 | If you wish to use our groups functionality then you must let us know about the users in your system. Call this when you add a user to your own DB.
80 |
81 | now.SremoveUser(uId)
82 |
83 | Call this when you remove a user from your database.
84 |
85 | now.SloginUser(uId, *callback, *args)
86 |
87 | Call this when a user logs in to your application. This will put him back into all the groups that he was subscribed to. Optionally, you can have a callback be called after a user is logged out. Note that if you wish to provide arguments they must be an array of arguments to your callback. Also note that your callback function must be in the `everyone.now` pocketspace.
88 |
89 | The reason the callback is necessary is that login performs a database operation and so if you were to call Sapply on any group the user is logged in, the user won't receive the function since the user won't be added to the group for a while as database operations are expensive.
90 |
91 | now.SlogoutUser(uId)
92 |
93 | Call this when a user logs out of your application. This will remove him from the groups that he was subscribed to but we will remember to put him back in those groups when he logs back in.
94 |
95 | now.subscribeToGroup(uId, groupId)
96 |
97 | Subscribes a user to a group, and adds him to the group.
98 |
99 | now.unsubscribeToGroup(uId, groupId)
100 |
101 | Unsubscribes a user from a group, and removes him from the group.
102 |
103 | Keep in mind that these are different from NowJS groups because these groups will persist beyond client log-in and log-out.
104 |
105 | #Client Side Initialization
106 |
107 | 1. Include dclient.js on the client side.
108 | 2. Call initialize with a JSON object of this type:
109 |
110 | ````javascript
111 | initialize({
112 | playback: playback(mediaInfo)
113 | })
114 | ````
115 |
116 | playback is your own provided function that takes mediaInfo as an argument. mediaInfo is of this form:
117 |
118 | ````javascript
119 | {
120 | path: path_to_media
121 | tags: [array, of, tags]
122 | metadata: JSON of your choice
123 | }
124 | ````
125 |
126 | ##Quickest Start Guide (tl;dr)
127 | 1. Include djs server side.
128 | 2. Initialize the client playback function.
129 | 3. Be super productive.
130 |
131 | FAQ
132 | ------
133 | **Q**: Did someone actually accidentally delete the entire codebase?
134 |
135 | A: No, he actually only deleted half of it.
136 |
137 | **Q**: What's up with the strange naming scheme? I don't like the C's and S's in front of your function names.
138 |
139 | A: It's because we've had trouble in the past writing code that utilized NowJS. Since it blurred the client server borders, we often got confused about whether functions were server-side or client-side, so to save us (and hopefully you!) from headaches we decided to do this.
140 |
141 | **Q**: What's the difference between rooms and groups?
142 |
143 | A: Rooms don't persist. If the server goes down, or the client disconnects, the client won't return to rooms they were connected to. Groups will persist.
144 |
145 | **Q**: What's up with your strange numbering scheme? Why does it start
146 | at 0.0.2?
147 |
148 | A: 0.0.0 was us claiming "djs" as a unique package name and 0.0.1 was us
149 | publishing something broken accidentally. Yes we realize we could have unpublished on npm but starting at 0.0.2 also lets us give the impression that we've already iterated once through a design cycle.
150 |
151 | Further Information
152 | ------------
153 | We have two examples at the moment. They're both incredibly hacky, but they were also built in about 30 minutes from scratch each, which includes all the wayward Facebook browsing. Information on how to run them is included in READMEs present in each example folder.
154 |
--------------------------------------------------------------------------------
/d.js:
--------------------------------------------------------------------------------
1 | var Db = require('mongodb').Db;
2 | var Connection = require('mongodb').Connection;
3 | var Server = require('mongodb').Server;
4 |
5 | var server
6 | var nowjs
7 | var everyone
8 |
9 | exports.initialize = function (theServer, nowObj, erryOne) {
10 | server = theServer
11 | nowjs = nowObj
12 | everyone = erryOne
13 |
14 | module.exports = everyone.now;
15 |
16 | var usercoll;
17 | var mediacoll;
18 | var db = new Db('djs', new Server("localhost", 27017, {}), {native_parser:false});
19 | db.open(function(err, conn) {
20 | db = conn;
21 | db.collection('userinfo', function(err, coll) {
22 | usercoll = coll;
23 | });
24 | db.collection('mediainfo', function(err, coll) {
25 | mediacoll = coll;
26 | });
27 | });
28 |
29 | everyone.now.SbroadcastMedia = function (mId, roomId) {
30 | var self = this
31 | if (roomId != undefined) {
32 | mediacoll.findOne({_id: new db.bson_serializer.ObjectID(mId)}, function (err, doc) {
33 | var room = nowjs.getGroup(roomId);
34 | room.now.playback(doc);
35 | });
36 | } else {
37 | mediacoll.findOne({_id: new db.bson_serializer.ObjectID(mId)}, function (err, doc) {
38 | everyone.now.playback(doc);
39 | });
40 | }
41 | }
42 |
43 | everyone.now.SgetCurrentMedia = function () {
44 |
45 | }
46 |
47 | everyone.now.SfindMedia = function (searchQuery, callback) {
48 | searchQuery = ("" + searchQuery).toLowerCase();
49 | var self = this;
50 | if (searchQuery === "") {
51 | var cursor = mediacoll.find({});
52 | cursor.toArray(function(err, array) {
53 | callback(array);
54 | });
55 | } else {
56 | var cursor = mediacoll.find({tags: searchQuery});
57 | cursor.toArray(function(err, array) {
58 | callback(array);
59 | });
60 | }
61 | }
62 |
63 | everyone.now.SaddMedia = function (path, tags, metadata) {
64 |
65 | mediacoll.insert(
66 | {
67 | path: path,
68 | tags: tags,
69 | metadata: metadata
70 | });
71 | }
72 |
73 |
74 | everyone.now.SaddToRoom = function (roomId) {
75 | var self = this;
76 | var group = nowjs.getGroup(roomId);
77 | group.addUser(self.user.clientId);
78 |
79 | }
80 |
81 | everyone.now.SleaveRoom = function (roomId) {
82 | var self = this;
83 | this.getGroups(function (groups) {
84 | if (roomId) {
85 | for (var i = groups.length; i--;) {
86 | if (groups[i] == roomId) {
87 | nowjs.getGroup(groups[i]).removeUser(self.user.clientId);
88 | }
89 | }
90 | } else {
91 | for (var i = groups.length; i--;) {
92 | nowjs.getGroup(groups[i]).removeUser(self.user.clientId);
93 | }
94 | }
95 | });
96 | }
97 |
98 | everyone.now.Sapply = function (functionName, args, roomId) {
99 | var room
100 | var fn
101 |
102 | if (args === undefined && roomId === undefined) { //did not provide args or roomId
103 | roomId = "everyone"
104 | args = []
105 | } else if (args instanceof Array && roomId === undefined) { //provided args
106 | roomId = "everyone"
107 | } else if (args instanceof String) { //provided roomId
108 | roomId = args
109 | args = []
110 | } //provided errything
111 | var room = nowjs.getGroup(roomId);
112 | var fn = room.now[functionName]
113 | fn.apply(fn, args)
114 | }
115 |
116 | //groups prototypes
117 | everyone.now.SaddUser = function (uId) {
118 | var self = this;
119 |
120 | usercoll.insert(
121 | {
122 | uId: uId,
123 | groups: [ ]
124 | });
125 | }
126 |
127 | everyone.now.SremoveUser = function (uId) {
128 | var self = this;
129 |
130 | usercoll.remove(
131 | {
132 | uId: uId
133 | });
134 | }
135 |
136 | everyone.now.SloginUser = function (uId, callback, args) {
137 | var self = this;
138 | usercoll.findOne({uId: uId}, function (err,doc) {
139 | for( var i in doc.groups){
140 | nowjs.getGroup(doc.groups[i]).addUser(self.user.clientId)
141 | }
142 | if (args) {
143 | var room = nowjs.getGroup('everyone')
144 |
145 | var fn = room.now[callback]
146 | fn.apply(fn, args)
147 | } else if (callback) {
148 |
149 |
150 | var room = nowjs.getGroup('everyone')
151 | var fn = room.now[callback]
152 | fn.apply(fn, [])
153 | }
154 | });
155 |
156 |
157 | }
158 |
159 | everyone.now.SlogoutUser = function (uId, callback, args) {
160 | var self = this;
161 | usercoll.findOne({uId: uId}, function (err,doc) {
162 | for( var i in doc.groups){
163 | nowjs.getGroup(doc.groups[i]).removeUser(self.user.clientId)
164 | }
165 | if (args) {
166 | var room = nowjs.getGroup('everyone')
167 | var fn = room.now[callback]
168 | fn.apply(fn, args)
169 | } else if (callback) {
170 | var room = nowjs.getGroup('everyone')
171 | var fn = room.now[callback]
172 | fn.apply(fn, [])
173 | }
174 |
175 | });
176 | }
177 |
178 | everyone.now.subscribeToGroup = function (uId, groupId) {
179 | nowjs.getGroup(groupId).addUser(this.user.clientId);
180 | var self = this;
181 | usercoll.findOne({uId: uId}, function (err,doc) {
182 | var newdoc = doc.groups.push(groupId);
183 | usercoll.update({uId: uId}, doc, function (err, doc){
184 |
185 | });
186 |
187 |
188 | });
189 | }
190 |
191 | everyone.now.unsubscribeFromGroup = function (uId, groupId){
192 | nowjs.getGroup(groupId).removeUser(this.user.clientId);
193 | var self = this;
194 | usercoll.findOne({uId: uId}, function (err,doc) {
195 | var i = 0;
196 | while( doc.groups[i] != groupId && i < doc.groups.length ){
197 | if (i == doc.groups.length-1){
198 | return;
199 | }
200 | i = i + 1;
201 | }
202 |
203 |
204 |
205 | newdoc = doc.groups.splice(i,1);
206 |
207 | usercoll.update({groups: newdoc}, doc, function (err, doc){
208 |
209 | });
210 | })
211 | }
212 | }
213 |
--------------------------------------------------------------------------------
/dclient.js:
--------------------------------------------------------------------------------
1 | var initialize = function(args) {
2 | now.playback = args.playback
3 | }
4 |
5 |
--------------------------------------------------------------------------------
/djs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherinemarvin/DJS/1a7a79860abdcf056ef0406f4797dbf93ded1eeb/djs.png
--------------------------------------------------------------------------------
/examples/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherinemarvin/DJS/1a7a79860abdcf056ef0406f4797dbf93ded1eeb/examples/.DS_Store
--------------------------------------------------------------------------------
/examples/hackathon/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherinemarvin/DJS/1a7a79860abdcf056ef0406f4797dbf93ded1eeb/examples/hackathon/.DS_Store
--------------------------------------------------------------------------------
/examples/hackathon/EXAMPLEREADME:
--------------------------------------------------------------------------------
1 | How do I use this example???
2 |
3 | Fire up app.js and navigate to two pages on two tabs:
4 |
5 | 1. localhost/: This is the client splash page.
6 | 2. localhost/admin: This is where you control the media distribution. The three boxes run as follows:
7 | a: link to media source. This can be:
8 | 1. The HTML for embedding a Soundcloud song on your page.
9 | 2. A direct link to an image
10 | 3. A link to an HTML5 YouTube video.
11 | b: A tag for the audio type. Can be:
12 | 1. mp3
13 | 2. pic
14 | 3. video
15 | c: A search term so you can find the media.
16 |
17 | On the admin page there is also a search bar where you can search for items by keywords.
18 |
19 | You can also just click "Find Media" to find all the media you have stored in your database.
20 |
21 | Simply click on whatever appears in the "RESULTS" div to play the media, which will show up both on the admin page and on the client page.
22 |
--------------------------------------------------------------------------------
/examples/hackathon/app.js:
--------------------------------------------------------------------------------
1 | var express = require('express');
2 | var dj = require('../../d');
3 | var nowjs = require('now');
4 |
5 | server = express.createServer();
6 |
7 | var everyone = nowjs.initialize(server, {socketio:{"log level": process.argv[2]}});
8 |
9 | dj.initialize(server, nowjs, everyone);
10 |
11 | server.set('view options', {
12 | layout: false
13 | });
14 |
15 | server.set('view engine', 'ejs');
16 |
17 | // Configuration
18 | server.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
19 | server.set('views', __dirname + '/views');
20 | server.use(express.static(__dirname + '/static'));
21 |
22 |
23 |
24 | server.get('/', function (req, res){
25 | res.render("splash");
26 | });
27 |
28 | server.get('/admin', function (req, res) {
29 | res.render("porntable");
30 | })
31 |
32 | server.listen(80);
33 | console.log("Express server listening on port %d", server.address().port);
34 |
--------------------------------------------------------------------------------
/examples/hackathon/node_modules/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherinemarvin/DJS/1a7a79860abdcf056ef0406f4797dbf93ded1eeb/examples/hackathon/node_modules/.DS_Store
--------------------------------------------------------------------------------
/examples/hackathon/node_modules/.bin/express:
--------------------------------------------------------------------------------
1 | ../express/bin/express
--------------------------------------------------------------------------------
/examples/hackathon/node_modules/ejs:
--------------------------------------------------------------------------------
1 | /usr/local/lib/node_modules/ejs
--------------------------------------------------------------------------------
/examples/hackathon/node_modules/express:
--------------------------------------------------------------------------------
1 | /usr/local/lib/node_modules/express
--------------------------------------------------------------------------------
/examples/hackathon/node_modules/mongodb:
--------------------------------------------------------------------------------
1 | /usr/local/lib/node_modules/mongodb
--------------------------------------------------------------------------------
/examples/hackathon/node_modules/now:
--------------------------------------------------------------------------------
1 | /usr/local/lib/node_modules/now
--------------------------------------------------------------------------------
/examples/hackathon/static/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherinemarvin/DJS/1a7a79860abdcf056ef0406f4797dbf93ded1eeb/examples/hackathon/static/.DS_Store
--------------------------------------------------------------------------------
/examples/hackathon/static/d.js:
--------------------------------------------------------------------------------
1 | var initialize = function(args) {
2 | now.playback = args.playback
3 | }
4 |
5 |
--------------------------------------------------------------------------------
/examples/hackathon/static/master.css:
--------------------------------------------------------------------------------
1 | @font-face { font-family: Nice; src: url('nice.otf'); }
2 |
3 | body {
4 | background: #222;
5 | color: #FFFFFF;
6 | text-align:center;
7 | margin:0 auto;
8 | }
9 |
10 | #title {
11 | margin-top: 40px;
12 | padding: 15px;
13 | height: 90px;
14 | font-size: 80px;
15 | text-shadow: 0 1px 1px #000;
16 | color: #fff;
17 | font-family: Nice;
18 | }
--------------------------------------------------------------------------------
/examples/hackathon/static/nice.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherinemarvin/DJS/1a7a79860abdcf056ef0406f4797dbf93ded1eeb/examples/hackathon/static/nice.otf
--------------------------------------------------------------------------------
/examples/hackathon/static/node_modules/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherinemarvin/DJS/1a7a79860abdcf056ef0406f4797dbf93ded1eeb/examples/hackathon/static/node_modules/.DS_Store
--------------------------------------------------------------------------------
/examples/hackathon/static/node_modules/.bin/express:
--------------------------------------------------------------------------------
1 | ../express/bin/express
--------------------------------------------------------------------------------
/examples/hackathon/static/node_modules/djs/README.md:
--------------------------------------------------------------------------------
1 | ###DJS makes media-sharing sites easy to make!
2 |
3 | Check out the github
4 |
5 | Install from npm (doesn't actually work yet)
6 | ----------------
7 |
8 | `npm install djs` or `npm install djs -g` for a global installation.
9 |
10 | DJS is a Node.JS module built on top of Now and MongoDB
11 |
12 | ##Public API
13 |
14 | ```javascript
15 |
16 | var server = express.createServer(...)
17 | ...
18 | var dj = require('djs')
19 | dj.initialize(server)
20 |
21 | ```
22 |
23 | Note: Any arguments with * are optional
24 |
25 | #Bare Bones Server Side Functionality
26 | ------
27 |
28 | now.SbroadcastMedia(mId, *roomId, callback)
29 |
30 | By default it tells all the clients to display whatever media is indicated by mId. Supplying the roomId will only display the media to users in that particular room. You must search for the mId you want using `SfindMedia`. The callback expects an argument `mediainfo`, which is a JSON object of this form. The callback has to be in the now space.
31 |
32 | ````javascript
33 | {
34 | path: path_to_media
35 | tags: [array, of, tags]
36 | metadata: JSON of your choice
37 | }
38 | ````
39 |
40 | now.SfindMedia(searchQuery, callback)
41 |
42 | Crawls the database for media with the searchQuery as part of the tag and passes the result to the callback function as an array of JSON objects of this form:
43 |
44 | ````javascript
45 | {
46 | path: path_to_media
47 | tags: [array, of, tags]
48 | metadata: JSON of your choice
49 | }
50 | ````
51 |
52 | now.SaddMedia(path, tags, metadata)
53 |
54 | Adds the media to the database. path is just the path to the media in question; tags is an array of strings. Metadata is a JSON object of your choice!!!
55 |
56 | now.SaddToRoom(roomId)
57 |
58 | Adds the user who calls this function to the room.
59 |
60 | now.SleaveRoom(*roomId)
61 |
62 | By default, has the user who calls this function leave all the rooms, including the `everyone` namespace (i.e. a logout). When called with a roomId as an argument, has the user leave just that room.
63 |
64 | #Groups Server Side Functionality
65 | -----
66 | now.SaddUser(uId)
67 |
68 | Adds a user into our personal database.
69 |
70 | now.SremoveUser(uId)
71 |
72 | Removes a user from our personal database.
73 |
74 | now.SloginUser(uId)
75 |
76 | Logs a user out of our personal database.
77 |
78 | now.subscribeToGroup(uId, groupId)
79 |
80 | Subscribes a user to a group.
81 |
82 | now.unsubscribeToGroup(uId, groupId)
83 |
84 | Unsubscribes a user from a group.
85 |
86 | Inserts a user into our personal userdatabase.
87 |
88 | #Client Side Initialization
89 |
90 | 1. Include d.js on the client side.
91 | 2. Call initialize with a JSON object of this type:
92 | ````javascript
93 | initialize({
94 | playback: playback(mediaInfo)
95 | })
96 |
97 | ````
98 | playback is your own provided function that takes mediaInfo as an argument. mediaInfo is of this form:
99 |
100 | ````javascript
101 | {
102 | path: path_to_media
103 | tags: [array, of, tags]
104 | metadata: JSON of your choice
105 | }
106 | ````
107 |
108 | ##Quickest Start Guide
109 | 1. Include djs server side.
110 | 2. Initialize the client stuff.
111 |
112 | FAQ
113 | ------
114 | **Q**: Did someone actually accidentally delete the entire codebase?
115 |
116 | A: No, he actually only deleted half of it.
117 |
118 | **Q**: What's up with the strange naming scheme? I don't like the C's and S's in front of your function names.
119 |
120 | A: It's because we've had trouble in the past writing code that utilized NowJS. Since it blurred the client server borders, we often got confused about whether functions were server-side or client-side, so to save us (and hopefully you!) from headaches we decided to do this.
121 |
122 | Further Information
123 | ------------
124 | Rainbow Dash is the best pony <3
125 |
--------------------------------------------------------------------------------
/examples/hackathon/static/node_modules/djs/d.js:
--------------------------------------------------------------------------------
1 | var nowjs = require('now');
2 | var Db = require('mongodb').Db;
3 | var Connection = require('mongodb').Connection;
4 | var Server = require('mongodb').Server;
5 |
6 | var server
7 | exports.initialize = function (theServer) {
8 | server = theServer
9 | var everyone = nowjs.initialize(server, {socketio:{"log level": process.argv[2]}});
10 |
11 | module.exports = everyone.now;
12 |
13 | var usercoll;
14 | var mediacoll;
15 | var db = new Db('djs', new Server("localhost", 27017, {}), {native_parser:false});
16 | db.open(function(err, conn) {
17 | db = conn;
18 | db.collection('userinfo', function(err, coll) {
19 | usercoll = coll;
20 | });
21 | db.collection('mediainfo', function(err, coll) {
22 | mediacoll = coll;
23 | });
24 | });
25 |
26 | everyone.now.SbroadcastMedia = function (mId, roomId) {
27 | var self = this
28 | //usercoll.findOne({isKing: true}, function (err, doc) {
29 | // if (doc.uId == self.user.clientId) {
30 | if (roomId != undefined) {
31 | mediacoll.findOne({_id: new db.bson_serializer.ObjectID(mId)}, function (err, doc) {
32 | var room = nowjs.getGroup(roomId);
33 | room.now.playback(doc);
34 | //callback(doc)
35 | console.log(doc.metadata.t)
36 | });
37 | } else {
38 | mediacoll.findOne({_id: new db.bson_serializer.ObjectID(mId)}, function (err, doc) {
39 | console.log(doc)
40 | everyone.now.playback(doc);
41 | console.log(doc.metadata.t)
42 | //callback(doc);
43 | });
44 | }
45 | // }
46 | //});
47 | }
48 |
49 | everyone.now.SgetCurrentMedia = function () {
50 |
51 | }
52 |
53 | everyone.now.SfindMedia = function (searchQuery, callback) {
54 | searchQuery = ("" + searchQuery).toLowerCase();
55 | var self = this;
56 | if (searchQuery === "") {
57 | var cursor = mediacoll.find({});
58 | cursor.toArray(function(err, array) {
59 | callback(array);
60 | });
61 | } else {
62 | var cursor = mediacoll.find({tags: searchQuery});
63 | cursor.toArray(function(err, array) {
64 | callback(array);
65 | });
66 | }
67 | }
68 |
69 | everyone.now.SaddMedia = function (path, tags, metadata) {
70 |
71 | mediacoll.insert(
72 | {
73 | path: path,
74 | tags: tags,
75 | metadata: metadata
76 | });
77 | }
78 |
79 |
80 | everyone.now.SaddToRoom = function (roomId) {
81 | var self = this;
82 | var group = nowjs.getGroup(roomId);
83 | group.addUser(self.user.clientId);
84 |
85 | }
86 |
87 | everyone.now.SleaveRoom = function (roomId) {
88 | var self = this;
89 | this.getGroups(function (groups) {
90 | if (roomId) {
91 | for (var i = groups.length; i--;) {
92 | if (groups[i] == roomId) {
93 | nowjs.getGroup(groups[i]).removeUser(self.user.clientId);
94 | }
95 | }
96 | } else {
97 | for (var i = groups.length; i--;) {
98 | nowjs.getGroup(groups[i]).removeUser(self.user.clientId);
99 | }
100 | }
101 | });
102 | }
103 |
104 | everyone.now.Sapply = function (functionName, args, roomId) {
105 | console.log("huehuehue")
106 | var room
107 | var fn
108 |
109 | if (args === undefined && roomId === undefined) { //did not provide args or roomId
110 | console.log('nope')
111 | roomId = "everyone"
112 | args = []
113 | } else if (args instanceof Array && roomId === undefined) { //provided args
114 | console.log('guaranteed')
115 | roomId = "everyone"
116 | } else if (args instanceof String) { //provided roomId
117 | console.log('nonono')
118 | roomId = args
119 | args = []
120 | } //provided errything
121 | console.log(functionName + ' ' + args + ' ' + roomId)
122 | var room = nowjs.getGroup(roomId);
123 | var fn = room.now[functionName]
124 | fn.apply(fn, args)
125 | }
126 |
127 | //groups prototypes
128 | everyone.now.SaddUser = function (uId) {
129 | console.log("ADDING USER")
130 | var self = this;
131 |
132 | usercoll.insert(
133 | {
134 | uId: uId,
135 | groups: [ ]
136 | });
137 | }
138 |
139 | everyone.now.SremoveUser = function (uId) {
140 | var self = this;
141 |
142 | usercoll.remove(
143 | {
144 | uId: uId
145 | });
146 | }
147 |
148 | everyone.now.SloginUser = function (uId, callback, args) {
149 | var self = this;
150 | usercoll.findOne({uId: uId}, function (err,doc) {
151 | for( var i in doc.groups){
152 | nowjs.getGroup(doc.groups[i]).addUser(self.user.clientId)
153 | }
154 | if (args) {
155 | var room = nowjs.getGroup('everyone')
156 |
157 | var fn = room.now[callback]
158 | fn.apply(fn, args)
159 | } else if (callback) {
160 |
161 |
162 | var room = nowjs.getGroup('everyone')
163 | var fn = room.now[callback]
164 | fn.apply(fn, [])
165 | }
166 | });
167 |
168 |
169 | }
170 |
171 | everyone.now.SlogoutUser = function (uId, callback, args) {
172 | var self = this;
173 | usercoll.findOne({uId: uId}, function (err,doc) {
174 | for( var i in doc.groups){
175 | nowjs.getGroup(doc.groups[i]).removeUser(self.user.clientId)
176 | }
177 | if (args) {
178 | var room = nowjs.getGroup('everyone')
179 | var fn = room.now[callback]
180 | fn.apply(fn, args)
181 | } else if (callback) {
182 | var room = nowjs.getGroup('everyone')
183 | var fn = room.now[callback]
184 | fn.apply(fn, [])
185 | }
186 |
187 | });
188 | }
189 |
190 | everyone.now.subscribeToGroup = function (uId, groupId) {
191 | nowjs.getGroup(groupId).addUser(this.user.clientId);
192 | var self = this;
193 | usercoll.findOne({uId: uId}, function (err,doc) {
194 | var newdoc = doc.groups.push(groupId);
195 | usercoll.update({uId: uId}, doc, function (err, doc){
196 |
197 | });
198 |
199 |
200 | });
201 | }
202 |
203 | everyone.now.unsubscribeFromGroup = function (uId, groupId){
204 | nowjs.getGroup(groupId).removeUser(this.user.clientId);
205 | var self = this;
206 | usercoll.findOne({uId: uId}, function (err,doc) {
207 | var i = 0;
208 | while( doc.groups[i] != groupId && i < doc.groups.length ){
209 | if (i == doc.groups.length-1){
210 | return;
211 | }
212 | i = i + 1;
213 | }
214 |
215 |
216 |
217 | newdoc = doc.groups.splice(i,1);
218 |
219 | usercoll.update({groups: newdoc}, doc, function (err, doc){
220 |
221 | });
222 | })
223 | }
224 | }
225 |
--------------------------------------------------------------------------------
/examples/hackathon/static/node_modules/djs/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "author": "Kevin Hwang (kevinhwang.net)",
3 | "name": "djs",
4 | "description": "A media sharing framework",
5 | "version": "0.0.0",
6 | "repository": {
7 | "type": "git",
8 | "url": "git://github.com/khwang/DJS.git"
9 | },
10 | "main": "d",
11 | "engines": {
12 | "node": "~v0.4.10"
13 | },
14 | "dependencies": {},
15 | "devDependencies": {}
16 | }
17 |
--------------------------------------------------------------------------------
/examples/hackathon/static/node_modules/ejs:
--------------------------------------------------------------------------------
1 | /usr/local/lib/node_modules/ejs
--------------------------------------------------------------------------------
/examples/hackathon/static/node_modules/express:
--------------------------------------------------------------------------------
1 | /usr/local/lib/node_modules/express
--------------------------------------------------------------------------------
/examples/hackathon/static/node_modules/mongodb:
--------------------------------------------------------------------------------
1 | /usr/local/lib/node_modules/mongodb
--------------------------------------------------------------------------------
/examples/hackathon/static/node_modules/now:
--------------------------------------------------------------------------------
1 | /usr/local/lib/node_modules/now
--------------------------------------------------------------------------------
/examples/hackathon/views/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherinemarvin/DJS/1a7a79860abdcf056ef0406f4797dbf93ded1eeb/examples/hackathon/views/.DS_Store
--------------------------------------------------------------------------------
/examples/hackathon/views/d.js:
--------------------------------------------------------------------------------
1 | var initialize = function(args) {
2 | now.playback = args.playback
3 | }
4 |
5 |
--------------------------------------------------------------------------------
/examples/hackathon/views/index.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 | Huehuehue
4 |
5 |
6 |
7 |
8 |
66 |
67 |
68 |
69 |
70 |
71 | Cool story bro
72 |
Just click the "Find Media" button to get a list of the current media on the server, then click any of the buttons to change the media!
161 |
162 |
--------------------------------------------------------------------------------
/examples/turntable/views/porntable.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 | ADMIN PAGE OMG
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |