更改进入聊天室的逻辑,先连接WS再切换场景,顺便修改场景名
This commit is contained in:
@@ -144,8 +144,7 @@ PATH={--Network API paths
|
||||
auth="/auth",
|
||||
access="/auth/access",
|
||||
rooms="/online/rooms",
|
||||
enterRoom="/online/enterRoom/",
|
||||
chat="/chat",
|
||||
chat_room="/chat_room",
|
||||
}
|
||||
|
||||
--Game tables
|
||||
|
||||
@@ -248,7 +248,7 @@ return{
|
||||
rooms="Rooms",
|
||||
chat="Chat",
|
||||
},
|
||||
chat={
|
||||
net_chat={
|
||||
clear="Clear",
|
||||
send="Send",
|
||||
},
|
||||
|
||||
@@ -227,7 +227,7 @@ return{
|
||||
-- rooms="Rooms",
|
||||
-- chat="Chat",
|
||||
},
|
||||
chat={
|
||||
net_chat={
|
||||
-- clear="Clear",
|
||||
-- send="Send",
|
||||
},
|
||||
|
||||
@@ -231,7 +231,7 @@ return{
|
||||
-- rooms="Rooms",
|
||||
-- chat="Chat",
|
||||
},
|
||||
chat={
|
||||
net_chat={
|
||||
-- clear="Clear",
|
||||
-- send="Send",
|
||||
},
|
||||
|
||||
@@ -251,7 +251,7 @@ return{
|
||||
rooms="房间列表",
|
||||
chat="聊天室",
|
||||
},
|
||||
chat={
|
||||
net_chat={
|
||||
clear="清空",
|
||||
send="发送",
|
||||
},
|
||||
|
||||
@@ -40,11 +40,8 @@ function scene.sceneInit()
|
||||
end
|
||||
scrollPos=#texts
|
||||
TASK.new(focusAtTextbox)--Widgets are not initialized, so active after 1 frame
|
||||
TASK.new(TICK.ws_read)
|
||||
BG.set("none")
|
||||
wsConnect(
|
||||
TICK.wsCONN_connect,
|
||||
PATH.socket..PATH.chat.."?email="..urlEncode(USER.email).."&access_token="..urlEncode(USER.access_token)
|
||||
)
|
||||
end
|
||||
function scene.sceneBack()
|
||||
wsWrite("/quit")
|
||||
@@ -1,3 +1,25 @@
|
||||
local function tick_goChatRoom(task)
|
||||
local time=0
|
||||
while true do
|
||||
coroutine.yield()
|
||||
local wsconn,connErr=client.poll(task)
|
||||
if wsconn then
|
||||
WSCONN=wsconn
|
||||
SCN.go("net_chat")
|
||||
LOG.print(text.wsSuccessed,"warn")
|
||||
return
|
||||
elseif connErr then
|
||||
LOG.print(text.wsFailed..": "..connErr,"warn")
|
||||
return
|
||||
end
|
||||
time=time+1
|
||||
if time>360 then
|
||||
LOG.print(text.wsFailed..": "..text.httpTimeout,"message")
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local scene={}
|
||||
|
||||
function scene.sceneInit()
|
||||
@@ -7,7 +29,12 @@ end
|
||||
scene.widgetList={
|
||||
WIDGET.newButton{name="ffa", x=640, y=200,w=350,h=120,font=40,code=NULL},
|
||||
WIDGET.newButton{name="rooms", x=640, y=360,w=350,h=120,font=40,code=WIDGET.lnk_goScene("net_rooms")},
|
||||
WIDGET.newButton{name="chat", x=640, y=540,w=350,h=120,font=40,code=WIDGET.lnk_goScene("chat")},
|
||||
WIDGET.newButton{name="chat", x=640, y=540,w=350,h=120,font=40,code=function()
|
||||
wsConnect(
|
||||
tick_goChatRoom,
|
||||
PATH.socket..PATH.chat_room.."?email="..urlEncode(USER.email).."&access_token="..urlEncode(USER.access_token)
|
||||
)
|
||||
end},
|
||||
WIDGET.newButton{name="back", x=1140, y=640,w=170,h=80,font=40,code=WIDGET.lnk_BACK},
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ function Tick.httpREQ_getAccessToken(task)
|
||||
end
|
||||
end
|
||||
|
||||
local function tick_wsCONN_read()
|
||||
function Tick.ws_read()
|
||||
while true do
|
||||
coroutine.yield()
|
||||
if not WSCONN then return end
|
||||
@@ -60,26 +60,4 @@ local function tick_wsCONN_read()
|
||||
end
|
||||
end
|
||||
end
|
||||
function Tick.wsCONN_connect(task)
|
||||
local time=0
|
||||
while true do
|
||||
coroutine.yield()
|
||||
local wsconn,connErr=client.poll(task)
|
||||
if wsconn then
|
||||
WSCONN=wsconn
|
||||
TASK.new(tick_wsCONN_read)
|
||||
LOG.print(text.wsSuccessed,"warn")
|
||||
return
|
||||
elseif connErr then
|
||||
LOG.print(text.wsFailed..": "..connErr,"warn")
|
||||
return
|
||||
end
|
||||
time=time+1
|
||||
if time>360 then
|
||||
LOG.print(text.wsFailed..": "..text.httpTimeout,"message")
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Tick
|
||||
Reference in New Issue
Block a user