forked from mbk-lab/rui_orig
Bug fixing
This commit is contained in:
parent
ebcba7f9c2
commit
6c49f37f68
23
appServer.go
23
appServer.go
|
@ -169,10 +169,9 @@ func (app *application) postHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
command := obj.Tag()
|
command := obj.Tag()
|
||||||
|
startSession := false
|
||||||
|
|
||||||
if session == nil {
|
if session == nil || command == "startSession" {
|
||||||
switch command {
|
|
||||||
case "startSession":
|
|
||||||
events := make(chan DataObject, 1024)
|
events := make(chan DataObject, 1024)
|
||||||
bridge := createHttpBridge(req)
|
bridge := createHttpBridge(req)
|
||||||
response = bridge.response
|
response = bridge.response
|
||||||
|
@ -181,27 +180,22 @@ func (app *application) postHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
bridge.writeMessage(answer)
|
bridge.writeMessage(answer)
|
||||||
session.onStart()
|
session.onStart()
|
||||||
|
if command == "session-resume" {
|
||||||
|
session.onResume()
|
||||||
|
}
|
||||||
bridge.sendResponse()
|
bridge.sendResponse()
|
||||||
|
|
||||||
setSessionIDCookie(w, session.ID())
|
setSessionIDCookie(w, session.ID())
|
||||||
|
startSession = true
|
||||||
|
|
||||||
go sessionEventHandler(session, events, bridge)
|
go sessionEventHandler(session, events, bridge)
|
||||||
|
|
||||||
default:
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !startSession {
|
||||||
switch command {
|
switch command {
|
||||||
case "startSession":
|
|
||||||
|
|
||||||
case "nop":
|
case "nop":
|
||||||
session.sendResponse()
|
session.sendResponse()
|
||||||
/*
|
|
||||||
case "disconnect":
|
|
||||||
session.onDisconnect()
|
|
||||||
return
|
|
||||||
*/
|
|
||||||
case "session-close":
|
case "session-close":
|
||||||
session.onFinish()
|
session.onFinish()
|
||||||
session.App().removeSession(session.ID())
|
session.App().removeSession(session.ID())
|
||||||
|
@ -212,6 +206,7 @@ func (app *application) postHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
session.addToEventsQueue(obj)
|
session.addToEventsQueue(obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
io.WriteString(w, <-response)
|
io.WriteString(w, <-response)
|
||||||
for len(response) > 0 {
|
for len(response) > 0 {
|
||||||
|
|
56
app_post.js
56
app_post.js
|
@ -17,59 +17,7 @@ window.onload = function() {
|
||||||
sendMessage( sessionInfo() );
|
sendMessage( sessionInfo() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
window.onfocus = function() {
|
||||||
window.onload = function() {
|
|
||||||
socketUrl = document.location.protocol == "https:" ? "wss://" : "ws://"
|
|
||||||
socketUrl += document.location.hostname
|
|
||||||
const port = document.location.port
|
|
||||||
if (port) {
|
|
||||||
socketUrl += ":" + port
|
|
||||||
}
|
|
||||||
socketUrl += window.location.pathname + "ws"
|
|
||||||
|
|
||||||
socket = new WebSocket(socketUrl);
|
|
||||||
socket.onopen = socketOpen;
|
|
||||||
socket.onclose = socketClose;
|
|
||||||
socket.onerror = socketError;
|
|
||||||
socket.onmessage = function(event) {
|
|
||||||
window.execScript ? window.execScript(event.data) : window.eval(event.data);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
function socketOpen() {
|
|
||||||
sendMessage( sessionInfo() );
|
|
||||||
}
|
|
||||||
|
|
||||||
function socketReopen() {
|
|
||||||
sendMessage( "reconnect{session=" + sessionID + "}" );
|
|
||||||
}
|
|
||||||
|
|
||||||
function socketReconnect() {
|
|
||||||
if (!socket) {
|
|
||||||
socket = new WebSocket(socketUrl);
|
|
||||||
socket.onopen = socketReopen;
|
|
||||||
socket.onclose = socketClose;
|
|
||||||
socket.onerror = socketError;
|
|
||||||
socket.onmessage = function(event) {
|
|
||||||
window.execScript ? window.execScript(event.data) : window.eval(event.data);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function socketClose(event) {
|
|
||||||
console.log("socket closed")
|
|
||||||
socket = null;
|
|
||||||
if (!event.wasClean && windowFocus) {
|
|
||||||
window.setTimeout(socketReconnect, 10000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
function socketError(error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.onfocus = function(event) {
|
|
||||||
windowFocus = true
|
windowFocus = true
|
||||||
sendMessage( "session-resume{session=" + sessionID +"}" );
|
sendMessage( "session-resume{}" );
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,11 @@ window.onresize = function() {
|
||||||
scanElementsSize();
|
scanElementsSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onbeforeunload = function(event) {
|
window.onbeforeunload = function() {
|
||||||
sendMessage( "session-close{session=" + sessionID +"}" );
|
sendMessage( "session-close{session=" + sessionID +"}" );
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onblur = function(event) {
|
window.onblur = function() {
|
||||||
windowFocus = false
|
windowFocus = false
|
||||||
sendMessage( "session-pause{session=" + sessionID +"}" );
|
sendMessage( "session-pause{session=" + sessionID +"}" );
|
||||||
}
|
}
|
||||||
|
|
|
@ -526,7 +526,9 @@ func (session *sessionData) htmlPropertyValue(htmlID, name string) string {
|
||||||
func (session *sessionData) handleAnswer(command string, data DataObject) bool {
|
func (session *sessionData) handleAnswer(command string, data DataObject) bool {
|
||||||
switch command {
|
switch command {
|
||||||
case "answer":
|
case "answer":
|
||||||
|
if session.bridge != nil {
|
||||||
session.bridge.answerReceived(data)
|
session.bridge.answerReceived(data)
|
||||||
|
}
|
||||||
|
|
||||||
case "imageLoaded":
|
case "imageLoaded":
|
||||||
session.imageManager().imageLoaded(data)
|
session.imageManager().imageLoaded(data)
|
||||||
|
@ -538,7 +540,9 @@ func (session *sessionData) handleAnswer(command string, data DataObject) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if session.bridge != nil {
|
||||||
session.bridge.sendResponse()
|
session.bridge.sendResponse()
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue