/** * Generates a token from a device association. * Once the association is made, the token is generated by * making a hash with the two devices sockets IDs. */ public static function createToken(Association $association) { $playerSocketId = $association->getPlayerSocket()->resourceId; $mobileSocketId = $association->getMobileSocket()->resourceId; $token = md5($playerSocketId . '-' . $mobileSocketId); return $token; }
/** * Registers a completed association. * Once an association is completed, it is registered * using its token. */ protected function registerAssociation(Association $association) { $associationToken = Association::createToken($association); $this->completedAssociations[$associationToken] = $association; // now communicate token to the two devices $messageJson = json_encode(array('direction' => MessageTypes::BROADCAST, 'name' => MessageTypes::ASSOCIATED_WITH_TOKEN, 'data' => array('token' => $associationToken))); echo "Devices {$association->getPlayerSocket()->resourceId} and {$association->getMobileSocket()->resourceId} associated with token {$associationToken}"; $association->broadcast($messageJson); }