Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion angular/simple/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ angular.module('chatApp', ['open-chat-framework'])


// create a user for myself and store as ```me```
$scope.ChatEngine.connect(new Date().getTime(), {}, 'auth-key');
$scope.ChatEngine.connect(new Date().getTime());

$scope.ChatEngine.on('$.ready', (data) => {

Expand Down
59 changes: 58 additions & 1 deletion javascript/chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,64 @@
</div>
</div>
<script src="../node_modules/chat-engine/dist/chat-engine.js" type="text/javascript"></script>
<script src="chat.js" type="text/javascript"></script>
<script type="text/javascript">
const now = new Date().getTime();
const username = ['user', now].join('-');
const textInput = document.getElementById('chat-input');
const textOutput = document.getElementById('chat-output');

let sendChat = function() {}; // will be filled in when ChatEngine connects

const ChatEngine = ChatEngineCore.create({
publishKey: '',
subscribeKey: ''
}, {
globalChannel: 'chat-engine-demo-js',
debug: true
});

ChatEngine.onAny((a) => {
// console.log(a)
});

ChatEngine.connect(username, {
signedOnTime: now
});

ChatEngine.on('$.ready', (data) => {

data.me.direct.onAny((a) => {
console.log(a)
})

sendChat = function(e) {

ChatEngine.global.emit('message', {
text: textInput.value
});

textInput.value = '';

return false;

};

checkSubmit = function(e) {

if (e.keyCode == 13) {
sendChat();
}
}

ChatEngine.global.on('message', (payload) => {

let div = document.createElement("p");
div.innerHTML = payload.sender.uuid + ': ' + payload.data.text;
textOutput.appendChild(div);

});
});
</script>
</body>

</html>
40 changes: 39 additions & 1 deletion javascript/online-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,45 @@
</div>
<div id="chat-online"></div>
<script src="../node_modules/chat-engine/dist/chat-engine.js" type="text/javascript"></script>
<script src="onlineList.js" type="text/javascript"></script>
<script type="text/javascript">
const now = new Date().getTime();
const username = ['user', now].join('-');

const onlineOutput = document.getElementById('online-list');

const ChatEngine = ChatEngineCore.create({
publishKey: 'pub-c-d8599c43-cecf-42ba-a72f-aa3b24653c2b',
subscribeKey: 'sub-c-6c6c021c-c4e2-11e7-9628-f616d8b03518'
}, {
debug: true,
globalChannel: 'chat-engine-online-example'
});

ChatEngine.on('$.ready', () => {

let onlineEvents = 0;

ChatEngine.global.on('$.online.*', (payload) => {

let div = document.createElement("li");
div.innerHTML = payload.user.uuid;
div.className += " list-group-item";
onlineOutput.appendChild(div);

onlineEvents++;

});

setInterval(function() {
console.log('users online', ChatEngine.global.users);
}, 1000);

});

ChatEngine.connect(username, {
signedOnTime: now
});
</script>
</body>

</html>
2 changes: 1 addition & 1 deletion jquery/kitchen-sink/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ ChatEngine = ChatEngineCore.create({
let username = window.location.hash.substr(1);

// create a user for myself and store as ```me```
ChatEngine.connect(username || new Date().getTime().toString(), {}, 'auth-key');
ChatEngine.connect(username || new Date().getTime().toString());

ChatEngine.on('$.session.chat.join', (data) => {

Expand Down
2 changes: 1 addition & 1 deletion nodejs/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var ChatEngine = ChatEngineCore.create({
debug: false
});

ChatEngine.connect('robot', { username: 'rob-the-robot' }, 'auth-key');
ChatEngine.connect('robot', { username: 'rob-the-robot' });

var chats = {};

Expand Down
2 changes: 1 addition & 1 deletion react-native/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class PizzaTranslator extends Component {
ChatEngine.connect(username, {
signedOnTime: now,
email: new Date()
}, 'auth-key');
});

ChatEngine.on('$.ready', (data) => {

Expand Down
213 changes: 106 additions & 107 deletions react/src/index.js
Original file line number Diff line number Diff line change
@@ -1,107 +1,106 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import ChatEngineCore from 'chat-engine'

const now = new Date().getTime();
const username = ['user', now].join('-');

const ChatEngine = ChatEngineCore.create({
publishKey: 'pub-c-d8599c43-cecf-42ba-a72f-aa3b24653c2b',
subscribeKey: 'sub-c-6c6c021c-c4e2-11e7-9628-f616d8b03518'
}, {
globalChannel: 'chat-engine-react'
});

ChatEngine.connect(username, {
signedOnTime: now
}, 'auth-key');

class Message extends React.Component{
render () {
return ( <
div > { this.props.uuid }: { this.props.text } <
/div>
);
}
};

var createReactClass = require('create-react-class');
var Chat = createReactClass({

getInitialState: function() {
return {
messages: [],
chatInput: ''
};
},

setChatInput: function(event) {
this.setState({ chatInput: event.target.value })
},

sendChat: function() {

if (this.state.chatInput) {

ChatEngine.global.emit('message', {
text: this.state.chatInput
});

this.setState({ chatInput: '' })

}

},

componentDidMount: function() {

ChatEngine.global.on('message', (payload) => {

let messages = this.state.messages;

messages.push( <
Message key={ this.state.messages.length } uuid={ payload.sender.uuid } text={ payload.data.text }
/>
);

this.setState({
messages: messages
});

});

},

_handleKeyPress: function(e) {
if (e.key === 'Enter') {
this.sendChat();
}
},

render: function() {
return ( <
div >
<
div id="chat-output" > { this.state.messages } < /div> <
input id="chat-input"
type="text"
name=""
value={ this.state.chatInput } onChange={ this.setChatInput } onKeyPress={ this._handleKeyPress }
/> <
input type="button"
onClick={ this.sendChat } value="Send Chat" / >
<
/div>
);
},
});

ChatEngine.on('$.ready', () => {

ReactDOM.render( <
Chat / > ,
document.getElementById('root')
);

});
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import ChatEngineCore from 'chat-engine'

const now = new Date().getTime();
const username = ['user', now].join('-');

const ChatEngine = ChatEngineCore.create({
publishKey: '',
subscribeKey: ''
}, {
globalChannel: 'chat-engine-react'
});

ChatEngine.connect(username, {
signedOnTime: now
});

var Message = React.createClass({
render: function() {
return ( <
div > { this.props.uuid }: { this.props.text } <
/div>
);
}
});

var Chat = React.createClass({

getInitialState: function() {
return {
messages: [],
chatInput: ''
};
},

setChatInput: function(event) {
this.setState({ chatInput: event.target.value })
},

sendChat: function() {

if (this.state.chatInput) {

ChatEngine.global.emit('message', {
text: this.state.chatInput
});

this.setState({ chatInput: '' })

}

},

componentDidMount: function() {

ChatEngine.global.on('message', (payload) => {

let messages = this.state.messages;

messages.push( <
Message key = { this.state.messages.length } uuid = { payload.sender.uuid } text = { payload.data.text }
/>
);

this.setState({
messages: messages
});

});

},

_handleKeyPress: function(e) {
if (e.key === 'Enter') {
this.sendChat();
}
},

render: function() {
return ( <
div >
<
div id = "chat-output" > { this.state.messages } < /div> <
input id = "chat-input"
type = "text"
name = ""
value = { this.state.chatInput } onChange = { this.setChatInput } onKeyPress = { this._handleKeyPress }
/> <
input type = "button"
onClick = { this.sendChat } value = "Send Chat" / >
<
/div>
);
},
});

ChatEngine.on('$.ready', () => {

ReactDOM.render( <
Chat / > ,
document.getElementById('root')
);

});