mirror of
https://shylinux.com/x/volcanos
synced 2025-04-25 08:48:06 +08:00
add WSS
This commit is contained in:
parent
0b9bda4fe6
commit
0b198ad753
32
lib/misc.js
32
lib/misc.js
@ -61,5 +61,37 @@ Volcanos("misc", {help: "工具模块",
|
||||
typeof cb == "function" && cb(msg)
|
||||
}), delete(event.msg)
|
||||
}),
|
||||
WSS: shy("请求后端", {order: 0}, function(can, cb, onerror, onclose, onopen) {var meta = arguments.callee.meta
|
||||
var s = new WebSocket(location.protocol.replace("http", "ws")+"//"+location.host+"/space/?node=active&name=some&wssid="+can._wssid)
|
||||
can._socket = s
|
||||
s.onerror = onerror || function() {
|
||||
delete(can._socket), setTimeout(function() {
|
||||
can.misc.WSS(can, cb, onerror, onclose, onopen)
|
||||
}, 1000)
|
||||
}, s.onclose = onclose, s.onopen = onopen
|
||||
s.onmessage = function(event) {var order = ++meta.order
|
||||
try {
|
||||
var msg = JSON.parse(event.data||'{}')
|
||||
} catch (e) {
|
||||
var msg = {"result": [event.data]}
|
||||
}
|
||||
|
||||
// Event入口 -1.0
|
||||
msg = can.Event(event, msg)
|
||||
msg.Reply = function() {
|
||||
msg.Option("_target", msg.Option("_source"))
|
||||
can.Log(["wss", order, "result"].concat(msg.result).concat([msg]))
|
||||
delete(msg.detail)
|
||||
delete(msg.event), s.send(JSON.stringify(msg))
|
||||
}
|
||||
|
||||
try {
|
||||
can.Log(["wss", order].concat(msg.detail).concat([msg]))
|
||||
typeof cb == "function" && cb(event, msg)
|
||||
} catch (e) {
|
||||
msg.Reply(can.Log("err", e))
|
||||
}
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
|
@ -11,6 +11,12 @@ Volcanos("onimport", {help: "导入数据", list: [],
|
||||
Volcanos("onaction", {help: "组件交互", list: [],
|
||||
onkeydown: function(event, can) {
|
||||
switch (event.key) {
|
||||
case "k":
|
||||
can.Report(event, {x: 0, y: -30}, "scroll")
|
||||
break
|
||||
case "j":
|
||||
can.Report(event, {x: 0, y: 30}, "scroll")
|
||||
break
|
||||
case "Escape":
|
||||
break
|
||||
case " ":
|
||||
|
@ -13,6 +13,9 @@ Volcanos("onimport", {help: "导入数据", list: [],
|
||||
item.value = value
|
||||
})
|
||||
},
|
||||
scroll: function(event, can, value, cmd, output) {can.layout = value;
|
||||
output.parentElement.scrollBy(value.x, value.y)
|
||||
},
|
||||
river: function(event, can, value, cmd, output) {
|
||||
if (value == "update") {return}
|
||||
can.Conf("temp_river", value)
|
||||
|
@ -20,6 +20,27 @@ Volcanos("onimport", {help: "导入数据", list: [],
|
||||
}]}, {type: "br"},
|
||||
])
|
||||
},
|
||||
username: function(event, can, value, cmd, output) {
|
||||
return can._socket || (can._socket = can.misc.WSS(can, function(event, m) {
|
||||
if (m.detail) {
|
||||
switch (m.detail[0]) {
|
||||
case "share":
|
||||
case "pwd":
|
||||
m.Echo("hello world")
|
||||
|
||||
}
|
||||
m.Reply(m)
|
||||
} else {
|
||||
page.toast.Pane.Show(m.result.join(""))
|
||||
}
|
||||
|
||||
}, function() {
|
||||
can._socket.close()
|
||||
|
||||
}, null, function() {
|
||||
can.user.toast("WSS Open")
|
||||
}))
|
||||
},
|
||||
login: function(event, can, value, cmd, output) {
|
||||
if (!can.user.Cookie("sessid")) {can.Show(event, 400, 400); return}
|
||||
can.run(event||{}, ["check"], function(msg) {var user = msg.Result()
|
||||
|
Loading…
x
Reference in New Issue
Block a user