Skip to content

Commit

Permalink
Created build version
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Burkalev authored and Konstantin Burkalev committed Apr 27, 2018
1 parent 87634cb commit 5d4158b
Show file tree
Hide file tree
Showing 7 changed files with 1,349 additions and 419 deletions.
20 changes: 20 additions & 0 deletions lib/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ local wiolaConf = {
--},
challengeCallback = nil,
authCallback = nil
},
metaAPI = {
session = false,
subscription = false,
registration = false
}
}

Expand Down Expand Up @@ -117,6 +122,21 @@ function _M.config(config)
wiolaConf.wampCRA.authCallback = config.wampCRA.authCallback
end
end

if config.metaAPI then

if config.metaAPI.session ~= nil then
wiolaConf.metaAPI.session = config.metaAPI.session
end

if config.metaAPI.subscription ~= nil then
wiolaConf.metaAPI.subscription = config.metaAPI.subscription
end

if config.metaAPI.registration ~= nil then
wiolaConf.metaAPI.registration = config.metaAPI.registration
end
end
end

return _M
18 changes: 8 additions & 10 deletions lib/flushdb.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
--
-- Project: wiola
-- User: Konstantin Burkalev
-- Date: 06.04.17
--
---
--- Project: wiola
--- User: Konstantin Burkalev
--- Date: 06.04.17
---

local _M = {}

--
-- Cleans up all wiola sessions data in redis store
--
-- redis - Redis instance on which to operate
--
---
--- Cleans up all wiola sessions data in redis store
---
function _M.flushAll()

local conf = require("wiola.config").config()
Expand Down
50 changes: 36 additions & 14 deletions lib/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
--
local wsServer = require "resty.websocket.server"
local wiola = require "wiola"
local webSocket, wampServer, ok, err, bytes

local webSocket, err = wsServer:new({
webSocket, err = wsServer:new({
timeout = tonumber(ngx.var.wiola_socket_timeout, 10) or 100,
max_payload_len = tonumber(ngx.var.wiola_max_payload_len, 10) or 65535
})
Expand All @@ -15,39 +16,60 @@ if not webSocket then
return ngx.exit(444)
end

local wampServer, err = wiola:new()
wampServer, err = wiola:new()
if not wampServer then
return ngx.exit(444)
end

local sessionId, dataType = wampServer:addConnection(ngx.var.connection, ngx.header["Sec-WebSocket-Protocol"])

local function removeConnection(premature, sessionId)
local function removeConnection(_, sessId)

local config = require("wiola.config").config()
local store = require('wiola.stores.' .. config.store)

local ok, err = store:init(config.storeConfig)
ok, err = store:init(config)
if not ok then
else
store:removeSession(sessionId)
store:removeSession(sessId)
end
end

local function removeConnectionWrapper()
removeConnection(true, sessionId)
end

local ok, err = ngx.on_abort(removeConnectionWrapper)
ok, err = ngx.on_abort(removeConnectionWrapper)
if not ok then
ngx.exit(444)
end

while true do
local cliData, cliErr = wampServer:getPendingData(sessionId)
local cliData, data, typ, hflags

hflags = wampServer:getHandlerFlags(sessionId)
if hflags ~= nil then
if hflags.sendLast == true then
cliData = wampServer:getPendingData(sessionId, true)

if dataType == 'binary' then
bytes, err = webSocket:send_binary(cliData)
else
bytes, err = webSocket:send_text(cliData)
end

if not bytes then
end
end

if hflags.close == true then
ngx.timer.at(0, removeConnection, sessionId)
return ngx.exit(444)
end
end
cliData = wampServer:getPendingData(sessionId)

while cliData ~= ngx.null do
local bytes, err
if dataType == 'binary' then
bytes, err = webSocket:send_binary(cliData)
else
Expand All @@ -57,26 +79,26 @@ while true do
if not bytes then
end

cliData, cliErr = wampServer:getPendingData(sessionId)
cliData = wampServer:getPendingData(sessionId)
end

if webSocket.fatal then
ngx.timer.at(0, removeConnection, sessionId)
return ngx.exit(444)
end

local data, typ, err = webSocket:recv_frame()
data, typ = webSocket:recv_frame()

if not data then

local bytes, err = webSocket:send_ping()
bytes, err = webSocket:send_ping()
if not bytes then
ngx.timer.at(0, removeConnection, sessionId)
return ngx.exit(444)
end

elseif typ == "close" then
local bytes, err = webSocket:send_close(1000, "Closing connection")
bytes, err = webSocket:send_close(1000, "Closing connection")
if not bytes then
return
end
Expand All @@ -86,13 +108,13 @@ while true do

elseif typ == "ping" then

local bytes, err = webSocket:send_pong()
bytes, err = webSocket:send_pong()
if not bytes then
ngx.timer.at(0, removeConnection, sessionId)
return ngx.exit(444)
end

elseif typ == "pong" then
-- elseif typ == "pong" then

elseif typ == "text" then -- Received something texty
wampServer:receiveData(sessionId, data)
Expand Down
4 changes: 2 additions & 2 deletions lib/headers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

ngx.header["Server"] = "wiola/Lua v0.6.0"

function has(tab, val)
for index, value in ipairs (tab) do
local has = function(tab, val)
for _, value in ipairs (tab) do
if value == val then
return true
end
Expand Down
5 changes: 0 additions & 5 deletions lib/post-handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ local wiola = require "wiola"
local wampServer = wiola:new()
local realm = "testRealm"

local redisOk, redisErr = wampServer:setupRedis("unix:/tmp/redis.sock")
if not redisOk then
return ngx.exit(444)
end

ngx.req.read_body()
local req = ngx.req.get_body_data()

Expand Down
Loading

0 comments on commit 5d4158b

Please sign in to comment.