diff --git a/editor/editors.go b/editor/editors.go index c8f40fa..83a9ac9 100644 --- a/editor/editors.go +++ b/editor/editors.go @@ -1,11 +1,11 @@ // Copyright (c) 2014, B3log -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -43,10 +43,13 @@ func WSHandler(w http.ResponseWriter, r *http.Request) { conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024) editorChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()} - session.EditorWS[sid] = &editorChan - ret := map[string]interface{}{"output": "Editor initialized", "cmd": "init-editor"} - editorChan.Conn.WriteJSON(&ret) + err := editorChan.Conn.WriteJSON(&ret) + if nil != err { + return + } + + session.EditorWS[sid] = &editorChan glog.Infof("Open a new [Editor] with session [%s], %d", sid, len(session.EditorWS)) diff --git a/notification/notifications.go b/notification/notifications.go index bd89ab3..d8b39e7 100644 --- a/notification/notifications.go +++ b/notification/notifications.go @@ -1,11 +1,11 @@ // Copyright (c) 2014, B3log -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,9 +17,9 @@ package notification import ( "net/http" + "strconv" "time" - "strconv" "github.com/b3log/wide/conf" "github.com/b3log/wide/event" "github.com/b3log/wide/i18n" @@ -97,6 +97,12 @@ func WSHandler(w http.ResponseWriter, r *http.Request) { conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024) wsChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()} + ret := map[string]interface{}{"notification": "Notification initialized", "cmd": "init-notification"} + err := wsChan.Conn.WriteJSON(&ret) + if nil != err { + return + } + session.NotificationWS[sid] = &wsChan glog.V(4).Infof("Open a new [Notification] with session [%s], %d", sid, len(session.NotificationWS)) diff --git a/output/outputs.go b/output/outputs.go index 2eeb178..0bde0de 100644 --- a/output/outputs.go +++ b/output/outputs.go @@ -1,11 +1,11 @@ // Copyright (c) 2014, B3log -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -58,10 +58,13 @@ func WSHandler(w http.ResponseWriter, r *http.Request) { conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024) wsChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()} - session.OutputWS[sid] = &wsChan - ret := map[string]interface{}{"output": "Ouput initialized", "cmd": "init-output"} - wsChan.Conn.WriteJSON(&ret) + err := wsChan.Conn.WriteJSON(&ret) + if nil != err { + return + } + + session.OutputWS[sid] = &wsChan glog.V(4).Infof("Open a new [Output] with session [%s], %d", sid, len(session.OutputWS)) } diff --git a/session/sessions.go b/session/sessions.go index 69ad503..a4df297 100644 --- a/session/sessions.go +++ b/session/sessions.go @@ -1,11 +1,11 @@ // Copyright (c) 2014, B3log -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -126,10 +126,13 @@ func WSHandler(w http.ResponseWriter, r *http.Request) { conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024) wsChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()} - SessionWS[sid] = &wsChan - ret := map[string]interface{}{"output": "Session initialized", "cmd": "init-session"} - wsChan.Conn.WriteJSON(&ret) + err := wsChan.Conn.WriteJSON(&ret) + if nil != err { + return + } + + SessionWS[sid] = &wsChan glog.V(4).Infof("Open a new [Session Channel] with session [%s], %d", sid, len(SessionWS)) diff --git a/shell/shells.go b/shell/shells.go index 2f443f5..3485e48 100644 --- a/shell/shells.go +++ b/shell/shells.go @@ -1,11 +1,11 @@ // Copyright (c) 2014, B3log -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -89,10 +89,13 @@ func WSHandler(w http.ResponseWriter, r *http.Request) { conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024) wsChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()} - ShellWS[sid] = &wsChan - ret := map[string]interface{}{"output": "Shell initialized", "cmd": "init-shell"} - wsChan.Conn.WriteJSON(&ret) + err := wsChan.Conn.WriteJSON(&ret) + if nil != err { + return + } + + ShellWS[sid] = &wsChan glog.V(4).Infof("Open a new [Shell] with session [%s], %d", sid, len(ShellWS)) diff --git a/static/js/notification.js b/static/js/notification.js index dcab77b..2b0fdc3 100644 --- a/static/js/notification.js +++ b/static/js/notification.js @@ -35,6 +35,10 @@ var notification = { var data = JSON.parse(e.data), $notification = $('.bottom-window-group .notification > table'), notificationHTML = ''; + + if (data.cmd && "init-notification" === data.cmd) { + return; + } notificationHTML += '' + data.severity + '' + data.message