Merge pull request #4 from TwilioDevEd/update-chat-channels

Updated Chat SDK version and the way channels are created if not found
This commit is contained in:
Jeff Linwood
2017-03-06 09:13:06 -06:00
committed by GitHub
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/> <input id="chat-input" type="text" placeholder="say anything" autofocus/>
</section> </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="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="index.js"></script> <script src="index.js"></script>
</body> </body>

View File

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