Skip to content

Instantly share code, notes, and snippets.

@sunnygleason
Last active April 19, 2017 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnygleason/260df661ea292435734f80b3b6f5166f to your computer and use it in GitHub Desktop.
Save sunnygleason/260df661ea292435734f80b3b6f5166f to your computer and use it in GitHub Desktop.
Advanced BLOCKS Techniques - Channel Encryption & Meta Attributes UI
<!DOCTYPE html>
<html>
<head>
<title>Angular 2</title>
<script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script>
<script src="https://unpkg.com/zone.js@0.7.2/dist/zone.js"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.9/Reflect.js"></script>
<script src="https://unpkg.com/rxjs@5.0.1/bundles/Rx.js"></script>
<script src="https://unpkg.com/@angular/core/bundles/core.umd.js"></script>
<script src="https://unpkg.com/@angular/common/bundles/common.umd.js"></script>
<script src="https://unpkg.com/@angular/compiler/bundles/compiler.umd.js"></script>
<script src="https://unpkg.com/@angular/platform-browser/bundles/platform-browser.umd.js"></script>
<script src="https://unpkg.com/@angular/forms/bundles/forms.umd.js"></script>
<script src="https://unpkg.com/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js"></script>
<script src="https://unpkg.com/pubnub@4.3.3/dist/web/pubnub.js"></script>
<script src="https://unpkg.com/pubnub-angular2@1.0.0-beta.8/dist/pubnub-angular2.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" />
</head>
<body>
<main-component>
Loading...
</main-component>
<script>
var app = window.app = {};
app.main_component = ng.core.Component({
selector: 'main-component',
template: `
<div class="container">
<pre>
NOTE: make sure to update the PubNub keys below with your keys,
and ensure that the BLOCK settings are configured properly!
</pre>
<h3>MyApp BLOCKS Encryption Integration</h3>
Severity:
<br />
<select [(ngModel)]="severity">
<option value="high">high</option>
<option value="medium">medium</option>
<option value="low">low</option>
</select>
<br />
Message:
<br />
<input type="text" [(ngModel)]="toSend" placeholder="message" />
<input type="button" (click)="publish()" value="Send!" />
<hr/>
<br/>
<br/>
<ul>
<li *ngFor="let item of messages.slice()">
<div>{{JSON.stringify(item.message)}}</div>
<div *ngIf="item.message.severity == 'high'" class="label label-danger">HIGH - Ops API notification sent!</div>
<div *ngIf="item.message.severity == 'medium'" class="label label-warning">MEDIUM - SMS sent!</div>
<div *ngIf="item.message.severity == 'low'" class="label label-default">LOW - email sent!</div>
</li>
</ul>
</div>`
}).Class({
constructor: [PubNubAngular, function(pubnubService){
var self = this;
self.pubnubService = pubnubService;
self.channelName = 'encrypt-channel';
self.JSON = JSON;
self.messages = [];
self.toSend = "";
self.severity = "high";
pubnubService.init({
publishKey: 'YOUR_PUB_KEY',
subscribeKey: 'YOUR_SUB_KEY',
cipherKey: 'CHANGE_ME_TO_SUPER_SECRET_STRING',
ssl:true
});
pubnubService.subscribe({channels: [self.channelName], triggerEvents: true});
self.messages = pubnubService.getMessage(this.channelName,function(){
// no handler necessary, dynamic collection of msg objects
});
}],
publish: function(){
this.pubnubService.publish({
channel: this.channelName,
message: {text:this.toSend, severity:this.severity},
meta: {severity:this.severity}
});
this.toSend = "";
}
});
app.main_module = ng.core.NgModule({
imports: [ng.platformBrowser.BrowserModule, ng.forms.FormsModule],
declarations: [app.main_component],
providers: [PubNubAngular],
bootstrap: [app.main_component]
}).Class({
constructor: function(){}
});
document.addEventListener('DOMContentLoaded', function(){
ng.platformBrowserDynamic.platformBrowserDynamic().bootstrapModule(app.main_module);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment