Build a Realtime talk widget in five minutes, Pusher

Build a Realtime talk widget in five minutes

In this brief article we’ll display how to add a Realtime Talk widget to your web application or web page. Then we’ll provide you with a number of ideas of how to improve the widget by personalising it and integrating it more closely with your existing application.

We <Three Developers

This tutorial works best with a

FREE Pusher account

This tutorial assumes that you have signed up for Pusher already, and have your API keys available.

We will cover the following:

  • Adding the PusherChatWidget JavaScript library and CSS to your HTML view
  • Integrating the example backend code with your existing server

Very first things very first

If you have a github account and are blessed using git you can fork or clone the project from github (or download a zip instead).

Once you have the code you should make it accessible on your chosen web server hosting. For the purposes of getting up and running we’ll assume that the code is in a directory named pusher-realtime-chat-widget in the root of your app.

Add the dependencies

For the front-end we’ll need to include a few JavaScript libraries; the Pusher JavaScript library, jQuery, and the PusherChatWidget JavaScript library and stylesheet:

For the back-end use the suitable package management solution:

In the example above you’ll see that we’ve also passed in a 2nd options parameter to the PusherChatWidget constructor. This is so the widget knows where to make the AJAX requests to in order for the server to validate and then trigger talk messages. The value of chatEndPoint should be updated so that the following file is executed (depending on your server technology):

Create & update your config

Within the sample application you’ll find example configuration files.

Where next?

Now you’ve got your Pusher-Powered Realtime Talk widget up and running it’s time to consider how you can make this widget work with your site or application; how can you integrate it with your app and what features can you add to make it much more titillating, usable and valuable? Here are a few ideas:

Personalise by integrating with your existing user accounts

In the example widget we’re using Gravatar to personalise the talk. If a user supplies the optional email address we can use it to look up their Gravatar (Avatar) and display it along with their chosen nickname when they send a talk message. However, many applications already have user accounts so rather than using Gravatar it would be excellent to use the existing user account information.

For the moment the widget only supports a displayName and and pic and you can use your own by passing them into the Activity object constructor:

Add extra checking to incoming requests

Talk Messages

Whilst the widget does attempt to undress out any HTML characters it doesn’t attempt to eliminate any profanity or anything else that others might find offensive. It might be a good idea to substitute sweary words with funny pics or reject the messages altogether.

You could also add some funny easter eggs like substituting certain words with photos or kicking users out of the talk if they commence talking about something you just don’t like – hey it’s your app after all!

Cross-site request forgery (and similar)

You will also want to ensure that the call to your server code has come from your web page or app. For more information Google CSRF and see the Wikipedia entry on CSRF.

Only let a logged in user participate in the talk

This is a pretty elementary one. You could only display the talk widget if users are logged in. Or, you could only let users participate if they are logged in, otherwise they can only view what’s being discussed.

The best way of ensuring that only logged in users can use the talk widget is by using a private channel which requires that the subscription to the channel is authenticated.

Make it a site-wide talk widget

The widget presently looks at the URL of the page or web application and creates a channel based on that. You could make widget use just one channel name for the entire site so that all users on the website use the same channel. This can actually be done now by providing a channel name option when creating the PusherChatWidget object:

Treat unreliable connections

You can’t assure that the user of your web app has the best connection in the world so we’ve provided a way of accessing connection state events. You could update the widget so that it shows the state of the user’s connection. If the users can’t connect and the connection is unavailable then you could stop the user from using the widget and tell them that they emerge to be offline at the moment.

Display talk participants using Pusher Presence

We provide a way of watching who’s subscribed to a channel at any time through functionality we call Presence. You could update the talk widget to use a presence channel and then demonstrate who is online and participating in the talk at any time. You could also display events within the UI whenever a users joins or leaves the channel.

Storing a history of messages

The widget doesn’t save any of the messages to a database so we can’t pre-load any messages when it very first geysers. This also means messages aren’t searchable – which might be a nice feature.

Storing a user’s information in session state or a cookie

At the moment the widget converts to showcasing who a user is when they send their very first talk message. If they then navigate to a different page their information will be lost. If the widget were updated to store that information in the user session or a cookie then we could update the widget to display the user details on page fountain, and we wouldn’t need the user to re-enter them.

Questions

If you have any questions about the Pusher Realtime Talk Widget examples please get in touch or ask a question by posting an issue/question on the github project.

Build a Realtime talk widget in five minutes, Pusher

Build a Realtime talk widget in five minutes

In this brief article we’ll demonstrate how to add a Realtime Talk widget to your web application or web page. Then we’ll provide you with a number of ideas of how to improve the widget by personalising it and integrating it more closely with your existing application.

We <Trio Developers

This tutorial works best with a

FREE Pusher account

This tutorial assumes that you have signed up for Pusher already, and have your API keys available.

We will cover the following:

  • Adding the PusherChatWidget JavaScript library and CSS to your HTML view
  • Integrating the example backend code with your existing server

Very first things very first

If you have a github account and are glad using git you can fork or clone the project from github (or download a zip instead).

Once you have the code you should make it accessible on your chosen web server hosting. For the purposes of getting up and running we’ll assume that the code is in a directory named pusher-realtime-chat-widget in the root of your app.

Add the dependencies

For the front-end we’ll need to include a few JavaScript libraries; the Pusher JavaScript library, jQuery, and the PusherChatWidget JavaScript library and stylesheet:

For the back-end use the adequate package management solution:

In the example above you’ll see that we’ve also passed in a 2nd options parameter to the PusherChatWidget constructor. This is so the widget knows where to make the AJAX requests to in order for the server to validate and then trigger talk messages. The value of chatEndPoint should be updated so that the following file is executed (depending on your server technology):

Create & update your config

Within the sample application you’ll find example configuration files.

Where next?

Now you’ve got your Pusher-Powered Realtime Talk widget up and running it’s time to consider how you can make this widget work with your site or application; how can you integrate it with your app and what features can you add to make it much more arousing, usable and valuable? Here are a few ideas:

Personalise by integrating with your existing user accounts

In the example widget we’re using Gravatar to personalise the talk. If a user supplies the optional email address we can use it to look up their Gravatar (Avatar) and display it along with their chosen nickname when they send a talk message. However, many applications already have user accounts so rather than using Gravatar it would be superb to use the existing user account information.

For the moment the widget only supports a displayName and and picture and you can use your own by passing them into the Activity object constructor:

Add extra checking to incoming requests

Talk Messages

Whilst the widget does attempt to unclothe out any HTML characters it doesn’t attempt to liquidate any profanity or anything else that others might find offensive. It might be a good idea to substitute sweary words with funny pics or reject the messages altogether.

You could also add some funny easter eggs like substituting certain words with photos or kicking users out of the talk if they embark talking about something you just don’t like – hey it’s your app after all!

Cross-site request forgery (and similar)

You will also want to ensure that the call to your server code has come from your web page or app. For more information Google CSRF and see the Wikipedia entry on CSRF.

Only let a logged in user participate in the talk

This is a pretty ordinary one. You could only display the talk widget if users are logged in. Or, you could only let users participate if they are logged in, otherwise they can only view what’s being discussed.

The best way of ensuring that only logged in users can use the talk widget is by using a private channel which requires that the subscription to the channel is authenticated.

Make it a site-wide talk widget

The widget presently looks at the URL of the page or web application and creates a channel based on that. You could make widget use just one channel name for the entire site so that all users on the website use the same channel. This can actually be done now by providing a channel name option when creating the PusherChatWidget object:

Treat unreliable connections

You can’t ensure that the user of your web app has the best connection in the world so we’ve provided a way of accessing connection state events. You could update the widget so that it shows the state of the user’s connection. If the users can’t connect and the connection is unavailable then you could stop the user from using the widget and tell them that they show up to be offline at the moment.

Display talk participants using Pusher Presence

We provide a way of witnessing who’s subscribed to a channel at any time through functionality we call Presence. You could update the talk widget to use a presence channel and then display who is online and participating in the talk at any time. You could also demonstrate events within the UI whenever a users joins or leaves the channel.

Storing a history of messages

The widget doesn’t save any of the messages to a database so we can’t pre-load any messages when it very first fountains. This also means messages aren’t searchable – which might be a nice feature.

Storing a user’s information in session state or a cookie

At the moment the widget converts to displaying who a user is when they send their very first talk message. If they then navigate to a different page their information will be lost. If the widget were updated to store that information in the user session or a cookie then we could update the widget to demonstrate the user details on page explosion, and we wouldn’t need the user to re-enter them.

Questions

If you have any questions about the Pusher Realtime Talk Widget examples please get in touch or ask a question by posting an issue/question on the github project.

Build a Realtime talk widget in five minutes, Pusher

Build a Realtime talk widget in five minutes

In this brief article we’ll demonstrate how to add a Realtime Talk widget to your web application or web page. Then we’ll provide you with a number of ideas of how to improve the widget by personalising it and integrating it more closely with your existing application.

We <Trio Developers

This tutorial works best with a

FREE Pusher account

This tutorial assumes that you have signed up for Pusher already, and have your API keys available.

We will cover the following:

  • Adding the PusherChatWidget JavaScript library and CSS to your HTML view
  • Integrating the example backend code with your existing server

Very first things very first

If you have a github account and are glad using git you can fork or clone the project from github (or download a zip instead).

Once you have the code you should make it accessible on your chosen web server hosting. For the purposes of getting up and running we’ll assume that the code is in a directory named pusher-realtime-chat-widget in the root of your app.

Add the dependencies

For the front-end we’ll need to include a few JavaScript libraries; the Pusher JavaScript library, jQuery, and the PusherChatWidget JavaScript library and stylesheet:

For the back-end use the adequate package management solution:

In the example above you’ll see that we’ve also passed in a 2nd options parameter to the PusherChatWidget constructor. This is so the widget knows where to make the AJAX requests to in order for the server to validate and then trigger talk messages. The value of chatEndPoint should be updated so that the following file is executed (depending on your server technology):

Create & update your config

Within the sample application you’ll find example configuration files.

Where next?

Now you’ve got your Pusher-Powered Realtime Talk widget up and running it’s time to consider how you can make this widget work with your site or application; how can you integrate it with your app and what features can you add to make it much more arousing, usable and valuable? Here are a few ideas:

Personalise by integrating with your existing user accounts

In the example widget we’re using Gravatar to personalise the talk. If a user supplies the optional email address we can use it to look up their Gravatar (Avatar) and display it along with their chosen nickname when they send a talk message. However, many applications already have user accounts so rather than using Gravatar it would be fine to use the existing user account information.

For the moment the widget only supports a displayName and and photo and you can use your own by passing them into the Activity object constructor:

Add extra checking to incoming requests

Talk Messages

Whilst the widget does attempt to unclothe out any HTML characters it doesn’t attempt to eliminate any profanity or anything else that others might find offensive. It might be a good idea to substitute sweary words with funny photos or reject the messages altogether.

You could also add some funny easter eggs like substituting certain words with pics or kicking users out of the talk if they begin talking about something you just don’t like – hey it’s your app after all!

Cross-site request forgery (and similar)

You will also want to ensure that the call to your server code has come from your web page or app. For more information Google CSRF and see the Wikipedia entry on CSRF.

Only let a logged in user participate in the talk

This is a pretty plain one. You could only display the talk widget if users are logged in. Or, you could only let users participate if they are logged in, otherwise they can only view what’s being discussed.

The best way of ensuring that only logged in users can use the talk widget is by using a private channel which requires that the subscription to the channel is authenticated.

Make it a site-wide talk widget

The widget presently looks at the URL of the page or web application and creates a channel based on that. You could make widget use just one channel name for the entire site so that all users on the website use the same channel. This can actually be done now by providing a channel name option when creating the PusherChatWidget object:

Treat unreliable connections

You can’t ensure that the user of your web app has the best connection in the world so we’ve provided a way of accessing connection state events. You could update the widget so that it shows the state of the user’s connection. If the users can’t connect and the connection is unavailable then you could stop the user from using the widget and tell them that they show up to be offline at the moment.

Display talk participants using Pusher Presence

We provide a way of eyeing who’s subscribed to a channel at any time through functionality we call Presence. You could update the talk widget to use a presence channel and then display who is online and participating in the talk at any time. You could also demonstrate events within the UI whenever a users joins or leaves the channel.

Storing a history of messages

The widget doesn’t save any of the messages to a database so we can’t pre-load any messages when it very first fountains. This also means messages aren’t searchable – which might be a nice feature.

Storing a user’s information in session state or a cookie

At the moment the widget converts to demonstrating who a user is when they send their very first talk message. If they then navigate to a different page their information will be lost. If the widget were updated to store that information in the user session or a cookie then we could update the widget to display the user details on page blast, and we wouldn’t need the user to re-enter them.

Questions

If you have any questions about the Pusher Realtime Talk Widget examples please get in touch or ask a question by posting an issue/question on the github project.

Build a Realtime talk widget in five minutes, Pusher

Build a Realtime talk widget in five minutes

In this brief article we’ll demonstrate how to add a Realtime Talk widget to your web application or web page. Then we’ll provide you with a number of ideas of how to improve the widget by personalising it and integrating it more closely with your existing application.

We <Trio Developers

This tutorial works best with a

FREE Pusher account

This tutorial assumes that you have signed up for Pusher already, and have your API keys available.

We will cover the following:

  • Adding the PusherChatWidget JavaScript library and CSS to your HTML view
  • Integrating the example backend code with your existing server

Very first things very first

If you have a github account and are glad using git you can fork or clone the project from github (or download a zip instead).

Once you have the code you should make it accessible on your chosen web server hosting. For the purposes of getting up and running we’ll assume that the code is in a directory named pusher-realtime-chat-widget in the root of your app.

Add the dependencies

For the front-end we’ll need to include a few JavaScript libraries; the Pusher JavaScript library, jQuery, and the PusherChatWidget JavaScript library and stylesheet:

For the back-end use the adequate package management solution:

In the example above you’ll see that we’ve also passed in a 2nd options parameter to the PusherChatWidget constructor. This is so the widget knows where to make the AJAX requests to in order for the server to validate and then trigger talk messages. The value of chatEndPoint should be updated so that the following file is executed (depending on your server technology):

Create & update your config

Within the sample application you’ll find example configuration files.

Where next?

Now you’ve got your Pusher-Powered Realtime Talk widget up and running it’s time to consider how you can make this widget work with your site or application; how can you integrate it with your app and what features can you add to make it much more arousing, usable and valuable? Here are a few ideas:

Personalise by integrating with your existing user accounts

In the example widget we’re using Gravatar to personalise the talk. If a user supplies the optional email address we can use it to look up their Gravatar (Avatar) and display it along with their chosen nickname when they send a talk message. However, many applications already have user accounts so rather than using Gravatar it would be superb to use the existing user account information.

For the moment the widget only supports a displayName and and pic and you can use your own by passing them into the Activity object constructor:

Add extra checking to incoming requests

Talk Messages

Whilst the widget does attempt to disrobe out any HTML characters it doesn’t attempt to eliminate any profanity or anything else that others might find offensive. It might be a good idea to substitute sweary words with funny pics or reject the messages altogether.

You could also add some funny easter eggs like substituting certain words with pictures or kicking users out of the talk if they embark talking about something you just don’t like – hey it’s your app after all!

Cross-site request forgery (and similar)

You will also want to ensure that the call to your server code has come from your web page or app. For more information Google CSRF and see the Wikipedia entry on CSRF.

Only let a logged in user participate in the talk

This is a pretty elementary one. You could only display the talk widget if users are logged in. Or, you could only let users participate if they are logged in, otherwise they can only view what’s being discussed.

The best way of ensuring that only logged in users can use the talk widget is by using a private channel which requires that the subscription to the channel is authenticated.

Make it a site-wide talk widget

The widget presently looks at the URL of the page or web application and creates a channel based on that. You could make widget use just one channel name for the entire site so that all users on the website use the same channel. This can actually be done now by providing a channel name option when creating the PusherChatWidget object:

Treat unreliable connections

You can’t ensure that the user of your web app has the best connection in the world so we’ve provided a way of accessing connection state events. You could update the widget so that it shows the state of the user’s connection. If the users can’t connect and the connection is unavailable then you could stop the user from using the widget and tell them that they emerge to be offline at the moment.

Showcase talk participants using Pusher Presence

We provide a way of watching who’s subscribed to a channel at any time through functionality we call Presence. You could update the talk widget to use a presence channel and then display who is online and participating in the talk at any time. You could also demonstrate events within the UI whenever a users joins or leaves the channel.

Storing a history of messages

The widget doesn’t save any of the messages to a database so we can’t pre-load any messages when it very first explosions. This also means messages aren’t searchable – which might be a nice feature.

Storing a user’s information in session state or a cookie

At the moment the widget converts to displaying who a user is when they send their very first talk message. If they then navigate to a different page their information will be lost. If the widget were updated to store that information in the user session or a cookie then we could update the widget to demonstrate the user details on page blast, and we wouldn’t need the user to re-enter them.

Questions

If you have any questions about the Pusher Realtime Talk Widget examples please get in touch or ask a question by posting an issue/question on the github project.

Build a Realtime talk widget in five minutes, Pusher

Build a Realtime talk widget in five minutes

In this brief article we’ll showcase how to add a Realtime Talk widget to your web application or web page. Then we’ll provide you with a number of ideas of how to improve the widget by personalising it and integrating it more closely with your existing application.

We <Three Developers

This tutorial works best with a

FREE Pusher account

This tutorial assumes that you have signed up for Pusher already, and have your API keys available.

We will cover the following:

  • Adding the PusherChatWidget JavaScript library and CSS to your HTML view
  • Integrating the example backend code with your existing server

Very first things very first

If you have a github account and are glad using git you can fork or clone the project from github (or download a zip instead).

Once you have the code you should make it accessible on your chosen web server hosting. For the purposes of getting up and running we’ll assume that the code is in a directory named pusher-realtime-chat-widget in the root of your app.

Add the dependencies

For the front-end we’ll need to include a few JavaScript libraries; the Pusher JavaScript library, jQuery, and the PusherChatWidget JavaScript library and stylesheet:

For the back-end use the suitable package management solution:

In the example above you’ll see that we’ve also passed in a 2nd options parameter to the PusherChatWidget constructor. This is so the widget knows where to make the AJAX requests to in order for the server to validate and then trigger talk messages. The value of chatEndPoint should be updated so that the following file is executed (depending on your server technology):

Create & update your config

Within the sample application you’ll find example configuration files.

Where next?

Now you’ve got your Pusher-Powered Realtime Talk widget up and running it’s time to consider how you can make this widget work with your site or application; how can you integrate it with your app and what features can you add to make it much more arousing, usable and valuable? Here are a few ideas:

Personalise by integrating with your existing user accounts

In the example widget we’re using Gravatar to personalise the talk. If a user supplies the optional email address we can use it to look up their Gravatar (Avatar) and display it along with their chosen nickname when they send a talk message. However, many applications already have user accounts so rather than using Gravatar it would be good to use the existing user account information.

For the moment the widget only supports a displayName and and pic and you can use your own by passing them into the Activity object constructor:

Add extra checking to incoming requests

Talk Messages

Whilst the widget does attempt to undress out any HTML characters it doesn’t attempt to liquidate any profanity or anything else that others might find offensive. It might be a good idea to substitute sweary words with funny photos or reject the messages altogether.

You could also add some funny easter eggs like substituting certain words with photos or kicking users out of the talk if they embark talking about something you just don’t like – hey it’s your app after all!

Cross-site request forgery (and similar)

You will also want to ensure that the call to your server code has come from your web page or app. For more information Google CSRF and see the Wikipedia entry on CSRF.

Only let a logged in user participate in the talk

This is a pretty ordinary one. You could only display the talk widget if users are logged in. Or, you could only let users participate if they are logged in, otherwise they can only view what’s being discussed.

The best way of ensuring that only logged in users can use the talk widget is by using a private channel which requires that the subscription to the channel is authenticated.

Make it a site-wide talk widget

The widget presently looks at the URL of the page or web application and creates a channel based on that. You could make widget use just one channel name for the entire site so that all users on the website use the same channel. This can actually be done now by providing a channel name option when creating the PusherChatWidget object:

Treat unreliable connections

You can’t assure that the user of your web app has the best connection in the world so we’ve provided a way of accessing connection state events. You could update the widget so that it shows the state of the user’s connection. If the users can’t connect and the connection is unavailable then you could stop the user from using the widget and tell them that they show up to be offline at the moment.

Showcase talk participants using Pusher Presence

We provide a way of witnessing who’s subscribed to a channel at any time through functionality we call Presence. You could update the talk widget to use a presence channel and then display who is online and participating in the talk at any time. You could also display events within the UI whenever a users joins or leaves the channel.

Storing a history of messages

The widget doesn’t save any of the messages to a database so we can’t pre-load any messages when it very first fountains. This also means messages aren’t searchable – which might be a nice feature.

Storing a user’s information in session state or a cookie

At the moment the widget converts to demonstrating who a user is when they send their very first talk message. If they then navigate to a different page their information will be lost. If the widget were updated to store that information in the user session or a cookie then we could update the widget to demonstrate the user details on page blast, and we wouldn’t need the user to re-enter them.

Questions

If you have any questions about the Pusher Realtime Talk Widget examples please get in touch or ask a question by posting an issue/question on the github project.

Related video:

Leave a Reply