diff --git a/dist/js/statuswidget.js b/dist/js/statuswidget.js index 914888f..979e7ed 100644 --- a/dist/js/statuswidget.js +++ b/dist/js/statuswidget.js @@ -4522,7 +4522,7 @@ eval("module.exports = extend\n\nvar hasOwnProperty = Object.prototype.hasOwnPro /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var status_js_api__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! status-js-api */ \"./node_modules/status-js-api/index.js\");\n/* harmony import */ var status_js_api__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(status_js_api__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var murmur_client__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! murmur-client */ \"./node_modules/murmur-client/dist/browser.js\");\n/* harmony import */ var murmur_client__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(murmur_client__WEBPACK_IMPORTED_MODULE_1__);\n\n\n\nwindow.StatusWidget = function (channelName) {\n var channelTitle = document.createElement('h3');\n channelTitle.innerHTML = \"#\" + channelName;\n\n var chatBox = document.createElement('div');\n chatBox.className = \"chat\";\n\n var chatInput = document.createElement('input');\n chatInput.type = \"input\";\n chatInput.className = \"post\";\n chatInput.placeholder = \"Type a message..\";\n\n document.querySelectorAll(\"#status-chat-widget\")[0].className += \" _status-chat-widget\";\n document.querySelectorAll(\"._status-chat-widget\")[0].append(channelTitle);\n document.querySelectorAll(\"._status-chat-widget\")[0].append(chatBox);\n document.querySelectorAll(\"._status-chat-widget\")[0].append(chatInput);\n\n let server = new murmur_client__WEBPACK_IMPORTED_MODULE_1___default.a({\n protocols: [\"libp2p\"],\n signalServers: [\n \"/dns4/web-bridge.status.im/tcp/443/wss/p2p-webrtc-star\"\n ],\n bootnodes: []\n });\n server.start();\n\n const status = new status_js_api__WEBPACK_IMPORTED_MODULE_0___default.a();\n status.connectToProvider(server.provider, null);\n\n var lastMessageUser = \"\";\n\n status.joinChat(channelName, () => {\n status.onMessage(channelName, (err, data) => {\n if (err || !data) {\n console.dir(\"error receiving message\");\n console.dir(err);\n return;\n }\n const msg = JSON.parse(data.payload)[1][0];\n\n const message = { username: data.username, message: msg, pubkey: data.data.sig, data };\n let div = document.createElement('div');\n if (lastMessageUser === message.username) {\n div.innerHTML = \"\" + message.username + \" \";\n }\n //document.querySelectorAll(\"#chat\")[0].append(div);\n chatBox.append(div);\n lastMessageUser = message.username;\n\n var element = document.getElementById(\"chat\");\n element.scrollTop = element.scrollHeight;\n });\n\n //var input = document.getElementById(\"post\")\n\n chatInput.addEventListener(\"keyup\", function(event) {\n if (event.keyCode !== 13) {\n return\n }\n\n event.preventDefault();\n\n //var value = document.getElementById(\"post\").value;\n var value = chatInput.value;\n status.sendMessage(channelName, value);\n chatInput.value = \"\";\n });\n })\n}\n\n\n//# sourceURL=webpack:///./src/index.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var status_js_api__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! status-js-api */ \"./node_modules/status-js-api/index.js\");\n/* harmony import */ var status_js_api__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(status_js_api__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var murmur_client__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! murmur-client */ \"./node_modules/murmur-client/dist/browser.js\");\n/* harmony import */ var murmur_client__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(murmur_client__WEBPACK_IMPORTED_MODULE_1__);\n\n\n\nwindow.StatusWidget = function (channelName, chatWidget) {\n if (!channelName) { throw new Error(\"no channelName provider\"); }\n if (!chatWidget) { throw new Error(\"no DOM element for chat\"); }\n\n var channelTitle = document.createElement('h3');\n channelTitle.innerHTML = \"#\" + channelName;\n\n var chatBox = document.createElement('div');\n chatBox.className = \"chat\";\n\n var chatInput = document.createElement('input');\n chatInput.type = \"input\";\n chatInput.className = \"post\";\n chatInput.placeholder = \"Type a message..\";\n\n chatWidget.className += \" _status-chat-widget\";\n chatWidget.append(channelTitle);\n chatWidget.append(chatBox);\n chatWidget.append(chatInput);\n\n let server = new murmur_client__WEBPACK_IMPORTED_MODULE_1___default.a({\n protocols: [\"libp2p\"],\n signalServers: [\n \"/dns4/web-bridge.status.im/tcp/443/wss/p2p-webrtc-star\"\n ],\n bootnodes: []\n });\n server.start();\n\n const status = new status_js_api__WEBPACK_IMPORTED_MODULE_0___default.a();\n status.connectToProvider(server.provider, null);\n\n var lastMessageUser = \"\";\n\n status.joinChat(channelName, () => {\n status.onMessage(channelName, (err, data) => {\n if (err || !data) {\n console.dir(\"error receiving message\");\n console.dir(err);\n return;\n }\n const msg = JSON.parse(data.payload)[1][0];\n\n const message = { username: data.username, message: msg, pubkey: data.data.sig, data };\n let div = document.createElement('div');\n if (lastMessageUser === message.username) {\n div.innerHTML = \" \";\n } else {\n div.innerHTML = \"\" + message.username + \" \";\n }\n chatBox.append(div);\n lastMessageUser = message.username;\n\n var element = document.getElementById(\"chat\");\n element.scrollTop = element.scrollHeight;\n });\n\n chatInput.addEventListener(\"keyup\", function(event) {\n if (event.keyCode !== 13) {\n return\n }\n\n event.preventDefault();\n\n var value = chatInput.value;\n status.sendMessage(channelName, value);\n chatInput.value = \"\";\n });\n })\n}\n\n\n//# sourceURL=webpack:///./src/index.js?"); /***/ }), diff --git a/index.html b/index.html index efd0668..6a576a3 100644 --- a/index.html +++ b/index.html @@ -65,6 +65,6 @@
- + \";\n } else {\n div.innerHTML = \"