diff --git a/app.json b/app.json index 4bc8a6f..c84c117 100644 --- a/app.json +++ b/app.json @@ -5,7 +5,7 @@ "window":{ "backgroundTextStyle":"light", "navigationBarBackgroundColor": "#fff", - "navigationBarTitleText": "WeChat", + "navigationBarTitleText": "小程序聊天室", "navigationBarTextStyle":"black" } } diff --git a/pages/index/index.js b/pages/index/index.js index ac04522..6fe76da 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -8,7 +8,7 @@ var app = getApp() var message = ''; -var text = '!!!!!欢迎来到聊天室!!!!!'; +var text = ''; var user = {}; @@ -30,15 +30,16 @@ Page({ var that = this - websocket.connect(function(res) { - text = res.data +"\n" + text; - that.setData({ - text:text - }); - }) //调用应用实例的方法获取全局数据 app.getUserInfo(function(userInfo){ user = userInfo; + + websocket.connect(user, function(res) { + text = res.data +"\n" + text; + that.setData({ + text:text + }); + }) }) } }) diff --git a/utils/websocket.js b/utils/websocket.js index aefef20..c4dd64e 100644 --- a/utils/websocket.js +++ b/utils/websocket.js @@ -1,9 +1,9 @@ var url = 'ws://121.42.51.70:8080/ws'; -function connect (func) { +function connect (user, func) { wx.connectSocket({ - url: url + url: url + '?username='+user.nickName }); wx.onSocketMessage(func);