diff --git a/src/examples/chat/chat.go b/src/examples/chat/chat.go index ba54479a..70b2aa16 100644 --- a/src/examples/chat/chat.go +++ b/src/examples/chat/chat.go @@ -120,6 +120,8 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心", return case "rename": m.Cmd("aaa.auth", "username", m.Option("username"), "data", "nickname", arg[1]) + + case "weixin": } } diff --git a/usr/librarys/chat.js b/usr/librarys/chat.js index a0a4cd4a..6cd793a2 100644 --- a/usr/librarys/chat.js +++ b/usr/librarys/chat.js @@ -642,6 +642,14 @@ var page = Page({check: true, }) page.river.Pane.Show(), page.pane = page.action, page.plugin = kit.Selector(page.action, "fieldset")[0] page.action.Pane.Layout(ctx.Search("layout")? ctx.Search("layout"): kit.device.isMobile? "办公": "工作") - page.socket = page.WSS() + + function conn() { + page.socket = page.WSS(null, function() { + page.socket.close() + }, function() { + setTimeout(conn, 1000) + }) + } + conn() }, }) diff --git a/usr/librarys/context.js b/usr/librarys/context.js index 1a312d28..8fbd2d9d 100644 --- a/usr/librarys/context.js +++ b/usr/librarys/context.js @@ -204,7 +204,7 @@ ctx = context = { xhr.setRequestHeader("Accept", "application/json") xhr.send(args.join("&")) }, - WSS: function(cb) { + WSS: function(cb, onerror, onclose) { var s = new WebSocket(location.protocol.replace("http", "ws")+"//"+location.host+"/wss") s.onopen = function(event) { kit.Log(event) @@ -225,9 +225,11 @@ ctx = context = { } s.onerror = function(event) { kit.Log(event) + typeof onerror == "function" && onerror(event) } s.onclose = function(event) { kit.Log(event) + typeof onclose == "function" && onclose(event) } return s }, diff --git a/usr/librarys/example.js b/usr/librarys/example.js index ab95136e..ee1a1a53 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -142,10 +142,10 @@ function Page(page) { } if (page.check) { - false && kit.device.isWeiXin? page.login.Pane.Run(["weixin"], function(msg) { + kit.device.isWeiXin? page.login.Pane.Run(["weixin"], function(msg) { page.Include([ "https://res.wx.qq.com/open/js/jweixin-1.4.0.js", - "/static/librarys/weixin.js", + // "/static/librarys/weixin.js", ], function(event) { wx.error(function(res){}) wx.ready(function(){ @@ -437,7 +437,7 @@ function Page(page) { } return typeof page[args[0]] == "function" && kit._call(page[args[0]], args.slice(1)) }, - WSS: function(cb) { + WSS: function(cb, onerror, onclose) { return ctx.WSS(cb || (function(m) { if (m.detail) { page.action.Pane.Core(event, m, ["_cmd", m.detail], function(msg) { @@ -446,7 +446,7 @@ function Page(page) { } else { page.ontoast(m.result.join("")) } - })) + }), onerror, onclose) }, initToast: function() {}, @@ -464,6 +464,10 @@ function Page(page) { }) }]}, {type: "br"}, ]) + + if (kit.device.isWeiXin) { + kit.AppendChild(output, []) + } return { Login: function(username, password, cb) { field.Pane.Run([username, password], function(msg) {cb(msg.result && msg.result[0] || "")})