-
-
Save domadev812/0bd6e60a6472df53c7eb437b665aa561 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm install -g cordova |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.publish = function() { | |
PubNub.ngPublish({ | |
channel: $scope.channel, | |
message: "[" + $scope.userId + "] " + $scope.newMessage | |
}); | |
$scope.newMessage = ''; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cordova platform add ios | |
$ cordova build ios |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cordova emulate ios |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cordova create [folder name] [com.example.appname] [application name] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="format-detection" | |
content="telephone=no" /> | |
<meta name="msapplication-tap-highlight" | |
content="no" /> | |
<meta name="viewport" | |
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> | |
<!-- Required libraries for the chat --> | |
<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.17.0.js"></script> | |
<script src="https://cdn.pubnub.com/pubnub-crypto.min.js"></script> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script> | |
<script src="<location-of-PubNub-SDK>/pubnub-angular-4.0.2.min.js"></script> | |
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css"> | |
<title>PubNub Angular Mobile Chat</title> | |
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<div class="container" ng-app="PubNubAngularApp" ng-controller="ChatCtrl"> | |
<br /> | |
<h4>Online Users</h4> | |
<ul> | |
<li ng-repeat="user in users">{{user}}</li> | |
</ul> | |
<br /> | |
<h4>Chat History ({{messages.length}})</h4> | |
<form ng-submit='publish()'> | |
<input type="text" ng-model='newMessage' /> | |
<input type="submit" value="Send" /> | |
</form> | |
<br /> | |
<div class="well"> | |
<ul> | |
<li ng-repeat="message in messages">{{message}}</li> | |
</ul> | |
</div> | |
</div> | |
<script type="text/javascript" src="cordova.js"></script> | |
<script type="text/javascript" src="js/pubnubAngularApp.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pubnub.init({ | |
publishKey: 'your pub key', | |
subscribeKey: 'your sub key' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pubnub.subscribe({ | |
channels : [$scope.selectedChannel], | |
channelGroups: [$scope.selectedChannelGroup], | |
withPresence: true, | |
triggerEvents: ['message', 'presence', 'status'] | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$rootScope.$on(Pubnub.getMessageEventNameFor($scope.selectedChannel), function (ngEvent, envelope) { | |
$scope.$apply(function () { | |
// add message to the messages list | |
$scope.chatMessages.unshift(envelope.message); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$rootScope.$on(Pubnub.getPresenceEventNameFor($scope.selectedChannel), function (ngEvent, pnEvent) { | |
// apply presence event (join|leave) on users list | |
handlePresenceEvent(pnEvent); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pubnub.hereNow( | |
{ | |
channels: [$scope.channel], | |
channelGroups : ["cg1"], | |
includeUUIDs: true, | |
includeState: true | |
}, | |
function (status, response) { | |
// handle status, response | |
} | |
); | |
Pubnub.history( | |
{ | |
channel: $scope.channel, | |
reverse: false, // false is the default | |
count: 50, // 100 is the default | |
stringifiedTimeToken: true // false is the default | |
}, | |
function (status, response) { | |
// handle status, response | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment