Code Monkey home page Code Monkey logo

lua's Introduction

Please direct all Support Questions and Concerns to [email protected]

PubNub 3.5 Real-time Cloud Push API - for Corona and Moai

www.pubnub.com - PubNub Real-time Push Service in the Cloud.

###GET YOUR PUBNUB KEYS HERE: ###http://www.pubnub.com/account#api-keys

PubNub is a Massively Scalable Real-time Service for Web and Mobile Games. This is a cloud-based service for broadcasting Real-time messages to thousands of web and mobile clients simultaneously.

Be sure to check out the sample code in the platform examples directories for complete code examples!

require "pubnub"
require "crypto"
require "PubnubUtil"

local pubnub_obj = pubnub.new({
    publish_key = "demo",
    subscribe_key = "demo",
    secret_key = "demo",
    ssl = false,
    origin = "pubsub.pubnub.com"
})

Publish

pubnub_obj:publish({
        channel = channel,
        message = text,
        callback = function(r) --textout(r)
        end,
        error = function(r) textout(r)
        end
    })
})

Subscribe

    pubnub_obj:subscribe({
        channel = channel,
        connect = function()
            textout('Connected to channel ')
            textout(channel)
        end,
        callback = function(message)
            --print(message.data.message)
            textout(message)
        end,
        error = function()
            textout("Oh no!!! Dropped 3G Conection!")
        end,
    })

Unsubscribe

    multiplayer:unsubscribe({
        channel = channel,
    })
    textout( 'Disconnected from ' .. channel )

Detailed History

function detailedHistory(channel, count, reverse)
    pubnub_obj:history({
        channel = channel,
        count = count,
        reverse = reverse,
        callback = function(response)
            textout(response)
        end,
        error = function (response)
            textout(response)
        end
    })
end

local my_channel = 'hello_world'
detailedHistory( my_channel, 5, false )

Time

pubnub_obj:time(function(time)
    -- PRINT TIME
    print("PUBNUB SERVER TIME: " .. time)
end)

UUID

uuid = pubnub_obj.uuid
print("PUBNUB UUID: ", uuid)

here_now

function here_now(channel)
    pubnub_obj:here_now({
        channel = channel,
        limit = limit,
        callback = function(response)
            textout(response)
        end,
        error = function (response)
            textout(response)
        end
    })
end

local my_channel = 'hello-corona-demo-channel'
here_now( my_channel )

Presence/where-now

function presence( channel)
    pubnub_obj:where_how({
        channel = channel,
        callback = function(message)
            for i,v in pairs(message.payload.channels) do textout(i .. " " .. v) end
        end,
        error = function()
            textout("Oh no!!! Dropped 3G Conection!")
        end
    })
end

local my_channel = 'hello_world'
presence(my_channel)

Please direct all Support Questions and Concerns to [email protected]

lua's People

Contributors

maxpresman avatar premek avatar stephenlb avatar sveljko avatar vveljko avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.