Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ocf

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ocf - npm Package Compare versions

Comparing version 0.1.11 to 0.1.14

40

getting-started.md

@@ -1,5 +0,1 @@

# DEPRICATED! OUT OF DATE!
There have been breaking API changes and this document is no longer correct.
# Table of Contents

@@ -40,37 +36,17 @@ <!-- MarkdownTOC -->

* ```rltm``` - OCF is based off PubNub [rltm.js](https://github.com/pubnub/rltm.js) which lets you switch between PubNub and Socket.io just by changing your configuration. Check out [the rltm.js docs](https://github.com/pubnub/rltm.js) for more information.
* ```pubnub``` - Your PubNub configuration.
* ```globalChannel``` - This is the global channel that all clients are connected to automatically. It's used for global announcements, global presence, etc.
### Socket.io
### Create
```js
let OCF = OpenChatFramework.create({
rltm: {
service: 'socketio',
config: {
endpoint: 'http://localhost:8000',
}
},
globalChannel: 'ocf-root-channel'
});
```
### PubNub
```js
const OCF = OpenChatFramework.create({
rltm: {
service: 'pubnub',
config: {
publishKey: 'YOUR_PUB_KEY',
subscribeKey: 'YOUR_SUB_KEY'
}
},
globalChannel: 'ocf-root-channel'
publishKey: 'YOUR_PUB_KEY',
subscribeKey: 'YOUR_SUB_KEY'
});
```
## Connect to OCF Network
## Connect
Now we're going to connect to the network (defined in ```rltm``` config). In order to connect, we need to identify ourselves to the network.
Now we're going to connect to the PubNub network. In order to connect, we need to identify ourselves to the network.

@@ -94,3 +70,3 @@ ```

```js
let chat = new Chat('channel');
let chat = new OCF.Chat('channel');
```

@@ -105,3 +81,3 @@

```js
chat.send('message', 'my message');
chat.emit('message', 'my message');
```

@@ -108,0 +84,0 @@

2

package.json
{
"author": "Ian Jennings",
"name": "ocf",
"version": "0.1.11",
"version": "0.1.14",
"description": "Open Chat Framework",

@@ -6,0 +6,0 @@ "main": "src/index.js",

@@ -8,2 +8,6 @@ # OCF - Open Chat Framework

# Getting Started
Check out [the getting started guide](https://github.com/pubnub/open-chat-framework/tree/master/getting-started.md).
# Full Docs

@@ -10,0 +14,0 @@

@@ -1,2 +0,2 @@

"use strict";
"use strict";

@@ -57,4 +57,13 @@ // Allows us to create and bind to events. Everything in OCF is an event

*/
this.on = this.emitter.on.bind(this.emitter);
this._on = this.emitter.on.bind(this.emitter);
this.on = (event, cb) => {
// ensure the user exists within the global space
this.events[event] = this.events[event] || new Event(this, event);
this._on(event, cb);
};
this.off = this.emitter.off.bind(this.emitter);

@@ -83,2 +92,38 @@

class Event {
constructor(Chat, event) {
this.channel = [Chat.channel, event].join('.');
this.publish = (m) => {
OCF.pubnub.publish({
message: m,
channel: this.channel
});
}
this.onMessage = (m) => {
if(this.channel == m.channel) {
Chat.trigger(event, m.message);
}
}
OCF.pubnub.addListener({
message: this.onMessage
});
OCF.pubnub.subscribe({
channels: [this.channel],
withPresence: true
});
}
}
/**

@@ -167,4 +212,9 @@ * An OCF generic emitter that supports plugins and forwards

*/
this.channel = channel;
if(channel.indexOf(globalChannel) == -1) {
this.channel = [globalChannel, channel].join('.');
}
/**

@@ -179,2 +229,5 @@ * A list of users in this {{#crossLink "Chat"}}{{/crossLink}}. Automatically kept in sync,

this.events = {}
// whenever we get a message from the network

@@ -213,11 +266,31 @@ // run local trigger message

this.onMessage = (m) => {
this.history = (event, config = {}) => {
// if message is sent to this specific channel
if(this.channel == m.channel) {
this.trigger(m.message[0], m.message[1]);
}
this.events[event] = this.events[event] || new Event(this, event);
};
config.channel = this.events[event].channel;
OCF.pubnub.history(config, (status, response) => {
if(response.error) {
throw new Error(response.error);
} else {
response.messages.forEach((message) => {
// trigger the same event with the same data
// but the event name is now history:name rather than just name
// to distinguish it from the original live events
this.trigger(
['$history', event].join('.'),
message.entry);
});
}
});
}
this.onPresence = (presenceEvent) => {

@@ -315,7 +388,7 @@

OCF.pubnub.publish({
message: [event, payload],
channel: this.channel
});
// ensure the event exists within the global space
this.events[event] = this.events[event] || new Event(this, event);
this.events[event].publish(payload);
});

@@ -626,3 +699,3 @@

this.feed = new Chat(
[OCF.globalChat.channel, 'feed', uuid].join('.'));
[OCF.globalChat.channel, uuid, 'feed'].join('.'));

@@ -638,3 +711,3 @@ /**

this.direct = new Chat(
[OCF.globalChat.channel, 'direct', uuid].join('.'));
[OCF.globalChat.channel, uuid, 'direct'].join('.'));

@@ -641,0 +714,0 @@ // if the user does not exist at all and we get enough

@@ -90,2 +90,55 @@ "use strict";

let historyChan = 'history-chat-4';
describe('history plugin', function() {
it('should be created', function(done) {
let historychat = new OCF.Chat(historyChan);
let ready = false;
historychat.on('$ocf.ready', () => {
historychat.emit('message', {
text: 'hello world'
});
historychat.emit('message', {
text: 'hello world'
});
historychat.emit('message', {
text: 'hello world'
});
if(!ready) {
done();
ready = true;
}
})
});
it('history', function(done) {
this.timeout(10000);
let historychat2 = new OCF.Chat(historyChan);
historychat2.history('message');
console.log(historychat2)
historychat2.once("$history.message", (message) => {
assert.isOk(message);
done();
});
});
});
// let pluginchat;

@@ -92,0 +145,0 @@

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc