mirror of
https://github.com/status-im/status-chat-widget.git
synced 2025-02-23 09:48:18 +00:00
generate chat widget
This commit is contained in:
parent
c4890a89b4
commit
69c077dc03
3498
dist/js/main.js
vendored
Normal file
3498
dist/js/main.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -1,7 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="./dist/js/main.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script src="./dist/js/main.js"></script>
|
||||
<div id="status-chat-widget"></div>
|
||||
<script>StatusWidget("gitter-bridge");</script>
|
||||
</body>
|
||||
</html>
|
||||
|
59
src/index.js
59
src/index.js
@ -1,18 +1,51 @@
|
||||
import StatusJS from 'status-js-api';
|
||||
import Murmur from 'murmur-client';
|
||||
|
||||
let server = new Murmur({
|
||||
protocols: ["libp2p"],
|
||||
// signalServer: { host: '104.248.64.24', port: '9090', protocol: 'ws' },
|
||||
signalServers: [
|
||||
//"/dns4/cryptolife.status.im/tcp/443/wss/p2p-webrtc-star"
|
||||
"/dns4/web-bridge.status.im/tcp/443/wss/p2p-webrtc-star"
|
||||
],
|
||||
bootnodes: []
|
||||
});
|
||||
server.start();
|
||||
window.StatusWidget = function (channelName) {
|
||||
var chatBox = document.createElement('div');
|
||||
chatBox.id = "chat";
|
||||
|
||||
const status = new StatusJS();
|
||||
status.connectToProvider(server.provider, null);
|
||||
var chatInput = document.createElement('input');
|
||||
chatInput.type = "input";
|
||||
chatInput.id = "post";
|
||||
|
||||
console.dir("hello world!")
|
||||
document.querySelectorAll("#status-chat-widget")[0].append(chatBox);
|
||||
document.querySelectorAll("#status-chat-widget")[0].append(chatInput);
|
||||
|
||||
let server = new Murmur({
|
||||
protocols: ["libp2p"],
|
||||
signalServers: [
|
||||
"/dns4/web-bridge.status.im/tcp/443/wss/p2p-webrtc-star"
|
||||
],
|
||||
bootnodes: []
|
||||
});
|
||||
server.start();
|
||||
|
||||
const status = new StatusJS();
|
||||
status.connectToProvider(server.provider, null);
|
||||
|
||||
status.joinChat(channelName, () => {
|
||||
status.onMessage(channelName, (err, data) => {
|
||||
const msg = JSON.parse(data.payload)[1][0];
|
||||
|
||||
const message = { username: data.username, message: msg, pubkey: data.data.sig, data };
|
||||
let div = document.createElement('div');
|
||||
div.innerHTML = message.username + "> " + message.message;
|
||||
document.querySelectorAll("#chat")[0].append(div)
|
||||
})
|
||||
|
||||
var input = document.getElementById("post")
|
||||
|
||||
input.addEventListener("keyup", function(event) {
|
||||
if (event.keyCode !== 13) {
|
||||
return
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
var value = document.getElementById("post").value;
|
||||
status.sendMessage(channelName, value);
|
||||
document.getElementById("post").value = "";
|
||||
});
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user