Updated Chat SDK version and the way channels are created if not found

This commit is contained in:
Jeffrey Linwood
2017-03-06 09:12:08 -06:00
parent 0935adb68a
commit b743511d1d
2 changed files with 15 additions and 17 deletions

View File

@@ -19,7 +19,7 @@
<input id="chat-input" type="text" placeholder="say anything" autofocus/>
</section>
<script src="///media.twiliocdn.com/sdk/js/chat/releases/0.11.0/twilio-chat.min.js"></script>
<script src="///media.twiliocdn.com/sdk/js/chat/v0.11/twilio-chat.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="index.js"></script>
</body>

View File

@@ -63,23 +63,21 @@ $(function() {
var promise = chatClient.getChannelByUniqueName('general');
promise.then(function(channel) {
generalChannel = channel;
if (!generalChannel) {
// If it doesn't exist, let's create it
console.log('Creating general channel');
chatClient.createChannel({
uniqueName: 'general',
friendlyName: 'General Chat Channel'
}).then(function(channel) {
console.log('Created general channel:');
console.log(channel);
generalChannel = channel;
setupChannel();
});
} else {
console.log('Found general channel:');
console.log(generalChannel);
console.log('Found general channel:');
console.log(generalChannel);
setupChannel();
}).catch(function() {
// If it doesn't exist, let's create it
console.log('Creating general channel');
chatClient.createChannel({
uniqueName: 'general',
friendlyName: 'General Chat Channel'
}).then(function(channel) {
console.log('Created general channel:');
console.log(channel);
generalChannel = channel;
setupChannel();
}
});
});
}