Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1ab5bd4

Browse filesBrowse files
committed
peeled off JavaScript into its own repository for convenience.
0 parents  commit 1ab5bd4
Copy full SHA for 1ab5bd4

File tree

Expand file treeCollapse file tree

173 files changed

+23961
-0
lines changed
Open diff view settings
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

173 files changed

+23961
-0
lines changed
Open diff view settings
Collapse file

‎3.1/README.md‎

Copy file name to clipboard
+127Lines changed: 127 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API.
2+
http://www.pubnub.com/account
3+
4+
## TESTLING - (OPTIONAL)
5+
PubNub JavaScript API for Web Browsers
6+
uses Testling Cloud Service for QA and Deployment.
7+
http://www.testling.com/
8+
9+
You need this to run './test.sh' unit test.
10+
This is completely optional, however we love Testling.
11+
12+
13+
## PubNub 3.1 Real-time Cloud Push API - JAVASCRIPT
14+
http://www.pubnub.com - PubNub Real-time Push Service in the Cloud.
15+
http://www.pubnub.com/tutorial/javascript-push-api
16+
17+
PubNub is a blazingly fast cloud-hosted messaging service for building
18+
real-time web and mobile apps. Hundreds of apps and thousands of developers
19+
rely on PubNub for delivering human-perceptive real-time
20+
experiences that scale to millions of users worldwide. PubNub delivers
21+
the infrastructure needed to build amazing MMO games, social apps,
22+
business collaborative solutions, and more.
23+
24+
## SIMPLE EXAMPLE
25+
```html
26+
<div id=pubnub pub-key=demo sub-key=demo></div>
27+
<script src=http://cdn.pubnub.com/pubnub-3.1.min.js ></script>
28+
<script>
29+
30+
// LISTEN
31+
PUBNUB.subscribe({
32+
channel : "hello_world",
33+
callback : alert
34+
})
35+
36+
// SEND
37+
PUBNUB.publish({
38+
channel : "hello_world",
39+
message : "Hi."
40+
})
41+
42+
</script>
43+
```
44+
45+
## ADVANCED STYLE
46+
```html
47+
<div id=pubnub pub-key=demo sub-key=demo></div>
48+
<script src=http://cdn.pubnub.com/pubnub-3.1.min.js ></script>
49+
<script>(function(){
50+
// LISTEN FOR MESSAGES
51+
PUBNUB.subscribe({
52+
channel : "hello_world", // CONNECT TO THIS CHANNEL.
53+
restore : false, // STAY CONNECTED, EVEN WHEN BROWSER IS CLOSED
54+
// OR WHEN PAGE CHANGES.
55+
callback : function(message) { // RECEIVED A MESSAGE.
56+
alert(message)
57+
},
58+
connect : function() { // CONNECTION ESTABLISHED.
59+
PUBNUB.publish({ // SEND A MESSAGE.
60+
channel : "hello_world",
61+
message : "Hi from PubNub."
62+
})
63+
},
64+
disconnect : function() { // LOST CONNECTION.
65+
alert(
66+
"Connection Lost." +
67+
"Will auto-reconnect when Online."
68+
)
69+
},
70+
reconnect : function() { // CONNECTION RESTORED.
71+
alert("And we're Back!")
72+
}
73+
})
74+
})();</script>
75+
```
76+
77+
## SSL MODE
78+
79+
```html
80+
<div id=pubnub ssl=on></div>
81+
<script src=https://pubnub.a.ssl.fastly.net/pubnub-3.1.min.js></script>
82+
<script>(function(){
83+
84+
var pubnub = PUBNUB({
85+
publish_key : 'demo',
86+
subscribe_key : 'demo',
87+
origin : 'pubsub.pubnub.com',
88+
ssl : true
89+
});
90+
91+
pubnub.subscribe({
92+
channel : 'my_channel',
93+
connect : function() { /* ... */ },
94+
callback : function(message) {
95+
alert(JSON.stringify(message));
96+
}
97+
});
98+
99+
})();</script>
100+
```
101+
102+
## Using the PUBNUB init() Function
103+
104+
Sometimes you want to use create a PubNub Instance directly in JavaScript
105+
and pass the PubNub API Keys without using a DOM element.
106+
To do this, simply follow this `init` example:
107+
108+
```html
109+
<script src=http://cdn.pubnub.com/pubnub-3.1.min.js ></script>
110+
<script>(function(){
111+
112+
// INIT PubNub
113+
var pubnub = PUBNUB.init({
114+
publish_key : 'demo',
115+
subscribe_key : 'demo',
116+
origin : 'pubsub.pubnub.com'
117+
});
118+
119+
// LISTEN
120+
pubnub.subscribe({ channel : "hello_world", callback : alert })
121+
122+
// SEND
123+
pubnub.publish({ channel : "hello_world", message : "Hi." })
124+
125+
})();</script>
126+
```
127+
Collapse file

‎3.1/comet.swf‎

Copy file name to clipboard
1.11 KB
Binary file not shown.
Collapse file

‎3.1/crossdomain.xml‎

Copy file name to clipboard
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<cross-domain-policy>
3+
<allow-access-from domain="*" secure="false" />
4+
</cross-domain-policy>
Collapse file

‎3.1/examples/presence/index.html‎

Copy file name to clipboard
+117Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<html>
2+
<head>
3+
<title>PubNub Presence Demo</title>
4+
5+
<style>
6+
body { height: auto; bottom:0; top:0; font-family: Verdana, Geneva, sans-serif; }
7+
table { border:2px solid #000; width: 100%; height:100%; border-collapse:collapse; }
8+
td { border:2px solid #000; vertical-align: top; padding: 10px; }
9+
td.history { width: 80%; }
10+
td.history .message { clear:both; font-size:12px; }
11+
td.history .message .sender { width: 150px; float:left; /*border:1px solid #000;*/ overflow: hidden; white-space: nowrap; font-weight: bold; }
12+
td.history .message .text { margin-left:155px; /*border:1px solid #000;*/ }
13+
td.chat { height: 19px; padding:0; }
14+
td.chat input { margin:0; }
15+
td.users { width: 20%; font-size: 14px; }
16+
td.users ul { padding-left: 20px; }
17+
td.history .join { text-align: center; color: gray; font-style: italic; font-size:12px; }
18+
td.chat input { width: 100%; }
19+
td.occupancy { text-align: right; padding: 0 10; vertical-align: middle; font-size: 14px; }
20+
input.example { color: #666; }
21+
</style>
22+
</head>
23+
<body>
24+
25+
<table>
26+
<tr>
27+
<td class="history">
28+
</td>
29+
<td class="users">
30+
<h3>Currently Here</h3>
31+
<ul class="list">
32+
</ul>
33+
</td>
34+
</tr>
35+
<tr>
36+
<td class="chat">
37+
<input />
38+
</td>
39+
<td class="occupancy">
40+
<span class='number'>0</span> people here now
41+
</td>
42+
</tr>
43+
</table>
44+
45+
46+
<div pub-key="demo" sub-key="demo" ssl="off" origin="pubsub.pubnub.com" id="pubnub"></div>
47+
<script src="../../pubnub-3.2.js"></script>
48+
49+
<script>(function(){
50+
51+
// LISTEN FOR MESSAGES
52+
PUBNUB.subscribe({
53+
channel : "presence_demo_chat", // CONNECT TO THIS CHANNEL.
54+
55+
restore : true, // STAY CONNECTED, EVEN WHEN BROWSER IS CLOSED
56+
// OR WHEN PAGE CHANGES.
57+
58+
callback : function(message) { // RECEIVED A MESSAGE.
59+
if (message['sender'] != PUBNUB.db.get($("#pubnub").attr('sub-key')+'uuid')) {
60+
messageEvent(message);
61+
}
62+
},
63+
connect : function() { // CONNECTION ESTABLISHED.
64+
65+
PUBNUB.history({channel: "presence_demo_chat", limit:100, callback: function(history) {
66+
for (i=0; i<history.length; i++) {
67+
messageEvent(history[i]);
68+
}
69+
}});
70+
71+
PUBNUB.here_now({channel:'presence_demo_chat', callback:function(message) {
72+
$("td.occupancy .number").text(message['occupancy']);
73+
for (i=0; i<message['uuids'].length; i++) {
74+
$(".users .list").append($("<li class='"+message['uuids'][i]+"'>"+message['uuids'][i]+"</li>"));
75+
}
76+
}});
77+
78+
},
79+
presence : function(message) {
80+
presenceEvent(message, true);
81+
}
82+
})
83+
})();</script>
84+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" ></script>
85+
<script src="js/jquery.example.min.js"></script>
86+
<script>
87+
function presenceEvent(message, announce) {
88+
if (announce == undefined) announce = true;
89+
//console.log("Got presence event: ", message, " announce ", announce);
90+
if (message['action'] == 'join') {
91+
$(".users .list").append($("<li class='"+message['uuid']+"'>"+message['uuid']+"</li>"));
92+
if (announce) $(".history").append($("<div class='join "+message['uuid']+"'>"+message['uuid']+" joined the channel</li>"));
93+
} else if (message['action'] == 'leave') {
94+
$(".users .list li."+message['uuid']).remove();
95+
if (announce) $(".history").append($("<div class='join "+message['uuid']+"'>"+message['uuid']+" left the channel</li>"));
96+
} else if (message['action'] == 'timeout') {
97+
$(".users .list li."+message['uuid']).remove();
98+
if (announce) $(".history").append($("<div class='join "+message['uuid']+"'>"+message['uuid']+" timed out</li>"));
99+
}
100+
$("td.occupancy .number").text(message['occupancy']);
101+
}
102+
function messageEvent(message) {
103+
//console.log("Got message: ", message);
104+
$(".history").append($("<div class='message'><div class='sender'>"+message['sender']+"</div><div class='text'>"+message['text']+"</div></div>"));
105+
}
106+
$("td.chat input").example("Chat here");
107+
$('td.chat input').keypress(function(e){
108+
if(e.which == 13){
109+
message = {sender:PUBNUB.db.get($("#pubnub").attr('sub-key')+'uuid'), text:$("td.chat input").val()};
110+
PUBNUB.publish({channel:'presence_demo_chat',message:message});
111+
messageEvent(message);
112+
$("td.chat input").val("");
113+
}
114+
});
115+
</script>
116+
</body>
117+
</html
Collapse file
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* jQuery Form Example Plugin 1.6.0
3+
* Populate form inputs with example text that disappears on focus.
4+
*
5+
* e.g.
6+
* $('input#name').example('Bob Smith');
7+
* $('input[@title]').example(function () {
8+
* return $(this).attr('title');
9+
* });
10+
* $('textarea#message').example('Type your message here', {
11+
* className: 'example_text'
12+
* });
13+
*
14+
* Copyright (c) Paul Mucur (http://mudge.name), 2007-2012.
15+
* Dual-licensed under the BSD (BSD-LICENSE.txt) and GPL (GPL-LICENSE.txt)
16+
* licenses.
17+
*
18+
* This program is free software; you can redistribute it and/or modify
19+
* it under the terms of the GNU General Public License as published by
20+
* the Free Software Foundation; either version 2 of the License, or
21+
* (at your option) any later version.
22+
*
23+
* This program is distributed in the hope that it will be useful,
24+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
25+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26+
* GNU General Public License for more details.
27+
*/(function(a){"use strict";var b;a.fn.on?b=function(b,c,d){a("body").on(c,b,d)}:a.fn.delegate?b=function(b,c,d){a("body").delegate(b,c,d)}:a.fn.live?b=function(b,c,d){a(b).live(c,d)}:b=function(b,c,d){a(b).bind(c,d)},a.fn.example=function(c,d){var e=a.isFunction(c),f=a.extend({},d,{example:c});return this.each(function(){var c,d=a(this);a.metadata?c=a.extend({},a.fn.example.defaults,d.metadata(),f):c=a.extend({},a.fn.example.defaults,f),a.fn.example.boundClassNames[c.className]||(a(window).bind("unload.example",function(){a("."+c.className).val("").removeClass(c.className)}),b("form","submit.example example:resetForm",function(){a(this).find("."+c.className).val("").removeClass(c.className)}),a.fn.example.boundClassNames[c.className]=!0),d.val()!==this.defaultValue&&(e||d.val()===c.example)&&d.val(this.defaultValue),d.val()===""&&!d.is(":focus")&&d.addClass(c.className).val(e?c.example.call(this):c.example),d.bind("focus.example",function(){a(this).is("."+c.className)&&a(this).val("").removeClass(c.className)}).bind("change.example",function(){a(this).is("."+c.className)&&a(this).removeClass(c.className)}).bind("blur.example",function(){a(this).val()===""&&a(this).addClass(c.className).val(e?c.example.call(this):c.example)})})},a.fn.example.defaults={className:"example"},a.fn.example.boundClassNames=[]})(jQuery);
Collapse file

‎3.1/examples/simple-chat.js‎

Copy file name to clipboard
+119Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
(function(){
2+
3+
/*
4+
PubNub Real Time Push APIs and Notifications Framework
5+
Copyright (c) 2010 Stephen Blum
6+
http://www.google.com/profiles/blum.stephen
7+
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation, either version 3 of the License, or
11+
(at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
/*
23+
24+
<!--
25+
Simple Chat
26+
===========
27+
28+
View source code on GitHub:
29+
http://github.com/pubnub/pubnub-api/blob/master/javascript/examples/simple-chat.js
30+
31+
<STYLE> inside <head>
32+
<DIV> where Simple Chat will appear.
33+
<SCRIPT> at BOTTOM of Page
34+
35+
To change the conversation channel,
36+
change the channel attribute inside the div.
37+
-->
38+
39+
<style>
40+
#simple-chat {padding:0;background-color:#c41952}
41+
#simple-chat-chatbox {height:60px;overflow:scroll;overflow-x:hidden;border:1px solid #ccc;padding:10px;background-color:#fff}
42+
#simple-chat-textbox {width:320px;margin:9px;font-size:18px}
43+
#simple-chat-button {width:70px;cursor:pointer;margin:9px;font-size:18px}
44+
</style>
45+
46+
<div id="simple-chat" channel="mychannel">Loading Simple Chat</div>
47+
48+
*/
49+
var P = PUBNUB
50+
, chat = {
51+
init : function( node_name ) {
52+
var node = P.$(node_name);
53+
54+
chat.node_name = node_name;
55+
56+
// Create Nodes
57+
chat.textbox = P.create('input');
58+
chat.chatbox = P.create('div');
59+
chat.button = P.create('button');
60+
61+
// Button Text
62+
chat.button.innerHTML = 'Send';
63+
64+
// Capture Channel
65+
var channel = P.attr( node, 'channel' );
66+
67+
// Add Styles
68+
P.attr( chat.chatbox, 'id', 'simple-chat-chatbox' );
69+
P.attr( chat.textbox, 'id', 'simple-chat-textbox' );
70+
P.attr( chat.button, 'id', 'simple-chat-button' );
71+
72+
// Display Nodes
73+
node.innerHTML = '';
74+
node.appendChild(chat.chatbox);
75+
node.appendChild(chat.textbox);
76+
node.appendChild(chat.button);
77+
78+
// Send Sign-on Message
79+
P.publish({
80+
channel : channel,
81+
message : 'Someone Joined the Chat.'
82+
});
83+
84+
function send(e) {
85+
var key = e.keyCode || e.charCode || 0
86+
, message = chat.textbox.value;
87+
88+
// Wait for Enter Key
89+
if (key != 13 && e.type == 'keydown' || !message) return true;
90+
91+
// Reset Value
92+
chat.textbox.value = '';
93+
94+
// Send Message
95+
P.publish({
96+
channel : node_name,
97+
message : message
98+
});
99+
}
100+
101+
// Bind Events
102+
P.bind( 'keydown', chat.textbox, send );
103+
P.bind( 'blur', chat.textbox, send );
104+
105+
// Register Listener
106+
P.subscribe({ channel : node_name }, chat.subscribe );
107+
},
108+
109+
subscribe : function(message) {
110+
var br = '<br/>';
111+
chat.chatbox.innerHTML = message + br + chat.chatbox.innerHTML;
112+
}
113+
114+
};
115+
116+
// Startup Simple Chat
117+
chat.init('simple-chat');
118+
119+
})()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.