Skip to content

Instantly share code, notes, and snippets.

@darkyen

darkyen/test.js

Created Feb 1, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.