• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

pubnub/lua: lua

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

pubnub/lua

开源软件地址(OpenSource Url):

https://github.com/pubnub/lua

开源编程语言(OpenSource Language):

Lua 99.7%

开源软件介绍(OpenSource Introduction):

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

PubNub 3.6 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

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
})

Signal

pubnub_obj:signal({
        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]




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap