|
1 | | -## --------------------------------------------------- |
2 | | -## |
3 | | -## YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API. |
4 | | -## http://www.pubnub.com/account |
5 | | -## |
6 | | -## USE "DEMO" INCLUDES (BELOW) FREE! WHILE DEVELOPING |
7 | | -## |
8 | | -## ---------------------------------------------------- |
9 | | - |
10 | | -## ------------------------------------------------------ |
11 | | -## PubNub 3.4.4 Real-time Cloud Push API - JAVASCRIPT webOS |
12 | | -## ------------------------------------------------------ |
13 | | -## |
14 | | -## 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 Massively Scalable Real-time Service for Web and Mobile Games. |
18 | | -## This is a cloud-based service for broadcasting Real-time messages |
19 | | -## to thousands of web and mobile clients simultaneously. |
20 | | - |
21 | | -<!-- ============================= --> |
22 | | -<!-- INCLUDE SCRIPT PREFERED STYLE --> |
23 | | -<!-- ============================= --> |
24 | | -<script src=pubnub.min.js></script> |
25 | | -<script>(function(){ |
26 | | - // ---------------------------------- |
27 | | - // INIT PUBNUB |
28 | | - // ---------------------------------- |
29 | | - var pubnub = PUBNUB({ |
30 | | - publish_key : 'demo', |
31 | | - subscribe_key : 'demo', |
32 | | - ssl : false, |
33 | | - origin : 'pubsub.pubnub.com' |
34 | | - }); |
35 | | - |
36 | | - // ---------------------------------- |
37 | | - // LISTEN FOR MESSAGES |
38 | | - // ---------------------------------- |
39 | | - pubnub.subscribe({ |
40 | | - channel : 'test', |
41 | | - callback : function(message) { |
42 | | - console.log(JSON.stringify(message)); |
43 | | - }, |
44 | | - error : function() { |
45 | | - // The internet is gone. |
46 | | - console.log("Connection Lost"); |
47 | | - } |
48 | | - }); |
49 | | - |
50 | | - // ---------------------------------- |
51 | | - // SEND MESSAGE |
52 | | - // ---------------------------------- |
53 | | - setInterval( function() { |
54 | | - pubnub.publish({ |
55 | | - channel : 'test', |
56 | | - message : { example : "Hello World!" }, |
57 | | - callback : function(info) { |
58 | | - if (info[0]) |
59 | | - console.log("Successfully Sent Message!"); |
60 | | - else |
61 | | - // The internet is gone. |
62 | | - console.log("Failed! -> " + info[1]); |
63 | | - } |
64 | | - }); |
65 | | - }, 1000 ); |
66 | | -})();</script> |
67 | | - |
68 | | -<!-- ============================= --> |
69 | | -<!-- SIMPLE EXAMPLE USE PUBNUB API --> |
70 | | -<!-- ============================= --> |
71 | | -<script> |
72 | | - // ---------------------------------- |
73 | | - // INIT PUBNUB |
74 | | - // ---------------------------------- |
75 | | - var pubnub = PUBNUB({ |
76 | | - publish_key : 'demo', |
77 | | - subscribe_key : 'demo', |
78 | | - ssl : false, |
79 | | - origin : 'pubsub.pubnub.com' |
80 | | - }); |
81 | | - |
82 | | - |
83 | | - // ------------------- |
84 | | - // LISTEN FOR MESSAGES |
85 | | - // ------------------- |
86 | | - pubnub.subscribe({ |
87 | | - channel : "hello_world", |
88 | | - callback : function(message) { alert(message) } |
89 | | - }) |
90 | | - |
91 | | - // ------------ |
92 | | - // SEND MESSAGE |
93 | | - // ------------ |
94 | | - pubnub.publish({ |
95 | | - channel : "hello_world", |
96 | | - message : "Hi." |
97 | | - }) |
98 | | - |
99 | | -</script> |
| 1 | +PubNub for JS Docs have been moved to: http://www.pubnub.com/docs/javascript/javascript-sdk.html |
0 commit comments