Created
February 1, 2016 02:48
-
-
Save darkyen/851be7148ca48d15b6ae to your computer and use it in GitHub Desktop.
foo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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