Skip to content

Instantly share code, notes, and snippets.

@darkyen
Created February 1, 2016 02:48
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 darkyen/851be7148ca48d15b6ae to your computer and use it in GitHub Desktop.
Save darkyen/851be7148ca48d15b6ae to your computer and use it in GitHub Desktop.
foo
export function openChannel(channelId){
return new Promise((resolve, reject) => {
const newChannel = new PusherGameChannel(channelId);
newChannel.once('connect', resolve);
newChannel.once('error', reject);
});
}
export async function openChannelWithServer(channelId){
const connection = await openChannel(channelId);
// connnecting
const interval = setInterval(() => {
connection.send('ping');
}, 1000);
return new Promise((resolve, reject) => {
connection.on(
'message',
({action}) => {
if( action === 'pong' ){
resolve(connection);
}
}
);
connection.on(
'error',
(err) => reject(err)
);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment