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